Ubuntu systems default to using the apt repository based on the country set during installation. These local repositories, distinguished by a two-character country code, help distribute the load and improve download speeds by reducing network latency.

Using multiple apt repositories ensures the main repository is not overwhelmed, offering efficient and faster access, especially when using local sources. However, network infrastructure and user demand can sometimes make foreign repositories more suitable.

Changing the apt repository source can be necessary for various reasons, such as technical issues, bandwidth limitations, or corporate policies. This can be easily done by updating the apt repository source file with the appropriate country code.

Steps to change apt source in Ubuntu:

  1. Launch the terminal.
  2. Backup the apt source file (optional).
    $ sudo cp -a /etc/apt/source.list /etc/apt/source.list.bak
    [sudo] password for user: 
  3. Edit the apt source file using a text editor to change the source or country of the apt repositories.
    $ sudo sed -i "s/\/jp\./\/us\./g" /etc/apt/sources.list
  4. 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.

  5. Upgrade installed packages using the new repositories.
    $ 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
Discuss the article:

Comment anonymously. Login not required.