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.

Steps to change apt source in Ubuntu:

  1. Open the terminal.
  2. 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: 
  3. Open the apt source file in a text editor.
  4. 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
  5. 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.

  6. 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
Discuss the article:

Comment anonymously. Login not required.