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.

Steps to change apt source in Ubuntu using the GUI:

  1. Open the “Software & Updates” utility from the application menu.
  2. Select the “Ubuntu Software” tab in “Software & Updates.”
  3. Choose “Download from:” and select the desired server or mirror from the dropdown list.
  4. Click “Close” to save changes and reload the package information when prompted.

    Ubuntu may ask to reload package lists immediately after selecting a new download source.

Steps to change apt source in Ubuntu from terminal:

  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.