HiBlog Linux and Windows Server
How to Set an Iranian Ubuntu APT Mirror Safely
- Ali GhanimatiAuthor
- Last updated
- 2 minutesReading time
- 4,582Views
- Ali Ghanimati
- Last updated:
- 2 min read
- 4,582 views
An APT mirror serves a copy of a package archive from another location. If updates from your Ubuntu server in Iran are slow, a closer mirror may help. Check that it is up to date and supports the installed release and architecture.
First identify which archive is slow or unavailable. Ubuntu has separate release, update, and security pockets. A blanket URL replacement can disrupt security updates. Back up your source configuration and check /etc/os-release and dpkg --print-architecture. Ubuntu archive mirror list.
Switch to the Iranian Ubuntu mirror with one command
If your main archive uses archive.ubuntu.com or a country hostname such as us.archive.ubuntu.com, use the command for the file that contains your active archive entry. If the same entry also serves the -security suite, move that suite to a separate entry using security.ubuntu.com before switching. Ubuntu package management and security updates.
Fresh installs of Ubuntu 24.04 and later typically use /etc/apt/sources.list.d/ubuntu.sources. This command updates the archive hostname on the URIs lines.
sudo sed -Ei.bak '/^[[:space:]]*URIs:/s#(https?://)([a-z]{2}\.)?archive\.ubuntu\.com(/ubuntu/?)([[:space:]]|$)#\1ir.archive.ubuntu.com\3\4#g' /etc/apt/sources.list.d/ubuntu.sourcesIf your entries are in the older /etc/apt/sources.list file, use this command for deb and deb-src lines.
sudo sed -Ei.bak '/^[[:space:]]*deb(-src)?[[:space:]]/s#(https?://)([a-z]{2}\.)?archive\.ubuntu\.com(/ubuntu/?)([[:space:]]|$)#\1ir.archive.ubuntu.com\3\4#g' /etc/apt/sources.listFor example, http://us.archive.ubuntu.com/ubuntu/ becomes http://ir.archive.ubuntu.com/ubuntu/. Both commands preserve security.ubuntu.com, ports.ubuntu.com, and settings such as Suites and Signed-By. Each saves a copy with the .bak suffix beside the original file. Keep the initial backup separately if you run the command again.
Verify the mirror
Run sudo apt update and check that it fetches package indexes from ir.archive.ubuntu.com and that your security repository also responds. If the mirror lacks your release or architecture, or you see a connection or signature error, copy the .bak file back over the original and run sudo apt update again.


