Ubuntu systems use an apt repository based on the country selected during installation. These repositories are identified by a country code, helping distribute the load and improving download speeds by reducing network latency. However, depending on network conditions, using a repository from another country might be more suitable.
Changing the apt repository source may be necessary due to technical issues, bandwidth limitations, or specific organizational requirements. Adjusting these sources allows for better performance and adherence to policies. This process is straightforward and involves editing the apt source list.
Updating the apt source list ensures that your system retrieves packages from the most appropriate repository. By selecting the correct repository, you can optimize download speeds and maintain system stability.
Related: Official Archive Mirrors for Ubuntu
Related: List of ISO 3166 country codes
Steps to change apt source in Ubuntu:
- Open the terminal.
- Create a backup of the apt source file (optional).
$ sudo cp -a /etc/apt/source.list /etc/apt/source.list.bak [sudo] password for user:
- Open the apt source file in a text editor.
- Change the source or country of the apt repositories.
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
- Update the apt package list from the new repositories.
$ 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.
- Upgrade the installed packages to ensure they are using the new sources.
$ 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 |
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.