Ubuntu systems rely on apt repositories distributed across various mirrors. The default mirror is typically based on the country selected during installation, reflecting ISO 3166 country codes. This arrangement leverages localized servers to reduce network latency and expedite package downloads.
Altering the apt repository source is often essential when facing network bottlenecks, resolving accessibility constraints, or complying with organizational requirements. Adjusting these sources can improve download performance and ensure alignment with system policies.
Precise control over the apt source list allows systems to retrieve packages from the most suitable mirrors. Configuring the right mirror helps optimize update speeds, reduces the likelihood of errors, and maintains stability on Ubuntu platforms.
Related: Official Archive Mirrors for Ubuntu
Related: List of ISO 3166 country codes
Ubuntu may ask to reload package lists immediately after selecting a new download source.
$ sudo cp -a /etc/apt/source.list /etc/apt/source.list.bak [sudo] password for user:
Replaces all instances of the Japanese repository URLs with the US ones in the apt sources list using sed directly at the terminal.
$ sudo sed -i "s/\/jp\./\/us\./g" /etc/apt/sources.list
$ sudo apt update Hit:1 http://ports.ubuntu.com/ubuntu-ports kinetic-security InRelease Get:2 http://us.ports.ubuntu.com/ubuntu-ports kinetic InRelease [267 kB] Get:3 http://us.ports.ubuntu.com/ubuntu-ports kinetic-updates InRelease [90.7 kB] Get:4 http://us.ports.ubuntu.com/ubuntu-ports kinetic-backports InRelease [90.7 kB] Get:5 http://us.ports.ubuntu.com/ubuntu-ports kinetic/main arm64 Packages [1,363 kB] ##### snipped
Step for apt update (above) is crucial before proceeding with package upgrade or installation.
$ sudo apt dist-upgrade --assume-yes
This guide is tested on Ubuntu:
| Version | Code Name |
|---|---|
| 22.04 LTS | Jammy Jellyfish |
| 23.10 | Mantic Minotaur |
| 24.04 LTS | Noble Numbat |