Ubuntu mirrors

People all over the world use Ubuntu Linux. In order to accommodate users from different regions of the world that wish to install updates or new software from Ubuntu’s official repositories, Canonical has “mirrors” all over the world.

For example, if all the software is hosted on servers in North America, that will provide a fast connection for some users, but users in Asia will have much higher latency to the servers and their downloads will take longer. Therefore it is necessary to have the content hosted on multiple servers in multiple regions.

On your Ubuntu system, your Ubuntu mirror should be selected automatically, but it is possible to change it manually. This can be useful if you notice that your system is connecting to a location that is far away, or your downloads are taking a long time. Let’s dive into the tutorial and see how this is configured via command line and GUI.

In this tutorial you will learn:

  • What is a download mirror?
  • How to change to the fastest download mirror via command line
  • How to change to the fastest download mirror via GNOME and KDE Plasma
  • How to run your own Ubuntu mirror with apt-mirror
Ubuntu mirrors
Ubuntu mirrors
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu Linux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

What is a download mirror?

Download mirrors are necessary so that one server does not get overwhelmed with many download requests coming in at once. Furthermore, download mirrors are spread out across the world, so that users from all regions will always have a server which will provide them with quick downloads.

These mirrors are the same all over. In other words, they all host the same, identical content. Software downloaded from an Ubuntu server in USA will yield the same results as software downloaded from Japan.

Ubuntu will automatically determine the best mirror for your system by checking what region you are in and running a quick test to nearby servers to see which one results in the speediest connection. As with pretty much anything else on Linux, we can always configure these settings manually if we choose.

An interesting tidbit of information is that not all the download mirrors are owned by Canonical. They certainly own some of them, but companies, universities, and individuals around the world also volunteer their server space and network bandwidth to helping out Ubuntu and acting as download mirrors.

How to change to the fastest download mirror

The are several different methods that can be used to change your system’s download mirror. Check out the various methods below.

Country Code

  1. The simplest approach is to make sure that your Ubuntu mirror defined within /etc/apt/sources.list includes a relevant country code appropriate to your location. For example, below you can find a official United States Ubuntu mirror as found in /etc/apt/sources.list:
    deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted
  2. If you are not located in United States simply overwrite the us country code with appropriate code of your country. That is, if your are located for example in Australia update your /etc/apt/sources.list file for all entries as:
    deb http://au.archive.ubuntu.com/ubuntu/ focal main restricted

Use mirror protocol

  1. Using mirror protocol as part of your /etc/apt/sources.list entry will instruct apt command to fetch mirrors located within your country only. In order to use mirror protocol update all lines within /etc/apt/sources.list file from the usual eg.:
    deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted


    deb mirror://mirrors.ubuntu.com/mirrors.txt focal main restricted
  2. Repeat the above for all relevant lines where appropriate. Alternatively, use sed command to automatically edit your /etc/apt/sources.list file. Update the below sed command where appropriate to fit your environment:
    $ sudo sed -i -e 's/http:\/\/us.archive/mirror:\/\/mirrors/' -e 's/\/ubuntu\//\/mirrors.txt/' /etc/apt/sources.list

Manual apt mirror selection

The above solutions look easy and they might just work for you. However, the mirror selected by apt may not be the fastest as it can be burdened by high latency. In this case you may try to choose your mirror manually from the list of mirrors located within your country.

Use wget command to retrieve the list. The below wget command will retrieve apt ubuntu mirrors related to your country. Example:

$ wget -qO - mirrors.ubuntu.com/mirrors.txt


You can see a list of available Ubuntu mirrors on the official archive mirrors website. Find your country, click on some of the servers, and perform a ping or traceroute test to see how speedy the connection is.

Based on your experience select the best mirror and alter your /etc/apt/sources.list apt configuration file appropriately.

Choosing the fastest mirror with netselect

This solution is preferred, as it guarantees the fastest mirror selection. For this we are going to use netselect command.

  1. The netselect package is not available within Ubuntu’s standard repository by default, so we will need to borrow it from Debian stable repository:
    $ sudo apt install wget
    $ wget http://ftp.us.debian.org/debian/pool/main/n/netselect/netselect_0.3.ds1-29_amd64.deb
    $ sudo dpkg -i netselect_0.3.ds1-29_amd64.deb
  2. Once you have the netselect command available on your Ubuntu system use it to locate the fastest mirror based on the lowest ICMP latency. The netselect output will be relative to your location. The below example output will show top 20 apt Ubuntu mirrors (if available):
    $ sudo netselect -s 20 -t 40 $(wget -qO - mirrors.ubuntu.com/mirrors.txt)
      134 https://mirror.us.leaseweb.net/ubuntu/
      142 http://mirrors.advancedhosters.com/ubuntu/
      147 http://ubuntu.osuosl.org/ubuntu/
      188 http://ubuntu.osuosl.org/ubuntu/
      195 http://mirror.us-ny2.kamatera.com/ubuntu/
      199 http://mirror.pit.teraswitch.com/ubuntu/
      211 https://nyc.mirrors.clouvider.net/ubuntu/
      213 http://mirror.brightridge.com/ubuntuarchive/
      213 http://mirror.math.princeton.edu/pub/ubuntu/
      220 http://ubuntu.mirror.constant.com/
      220 https://mirrors.bloomu.edu/ubuntu/
      225 http://ubuntu.mirror.frontiernet.net/ubuntu/
      227 http://www.club.cc.cmu.edu/pub/ubuntu/
      231 http://mirrors.tripadvisor.com/ubuntu/
      237 http://mirror.team-cymru.com/ubuntu/
      246 http://mirrors.gigenet.com/ubuntuarchive/
      246 http://mirror.siena.edu/ubuntu/
      250 http://us.mirror.nsec.pt/ubuntu/
      252 http://archive.linux.duke.edu/ubuntu/
      252 https://mirror.jacksontechnical.com/ubuntu/
    Using netselect command to determine the best Ubuntu mirror for us
    Using netselect command to determine the best Ubuntu mirror for us
  3. Alter manually your /etc/apt/sources.list file to reflect the above netselect results or use sed command, where the lower score number on the left represents a higher mirror transfer rate. Example:
    $ sudo sed -i 's/http:\/\/us.archive.ubuntu.com\/ubuntu\//http:\/\/ubuntu.uberglobalmirror.com\/archive\//' /etc/apt/sources.list

Change mirror via GUI

If you prefer to use the GUI over command line, and have either the GNOME or KDE desktop envrionment installed, you can use the following sections below to change your Ubuntu downlod mirror.


  1. Open the Software & Updates application, then click on the “Download From” drop down box.
    Open the download from box inside the Software & Updates application
    Open the download from box inside the Software & Updates application
  2. Manually scroll through the list and select your desired mirror, or alternatively just click the “Select best server” button to let Ubuntu do the work for you.
    Manually selecting download mirror via GNOME gui
    Manually selecting download mirror via GNOME gui

KDE Plasma

  1. Start by opening the Discover Software Center, then click on Settings and finally the “Software Sources” button.
    Open the Software Sources menu inside of the Discover Software Center application
    Open the Software Sources menu inside of the Discover Software Center application
  2. You will be required to enter your root password, and then you can expand the Download From menu and click on Other.
    Opening the download from box in KDE settings
    Opening the download from box in KDE settings
  3. Manually scroll through the list and select your desired mirror, or alternatively just click the “Select best server” button to let Ubuntu do the work for you.
    Manually selecting download mirror via KDE Plasma gui
    Manually selecting download mirror via KDE Plasma gui

How to run your own Ubuntu mirror

It is actually quite easy to host your own Ubuntu mirror. This is useful on a network that has a lot of Ubuntu computers. Rather than having each computer download their own updates, you could configure only one to act as an Ubuntu mirror, and have the rest of your computers download their updates from there.

This way, you are only downloading the updates one time, and then distributing them throughout your local area network very quickly.

This is faciliated by the apt-mirror command, which will download all of the latest software to your machine, and from there it can be distributed when other computers are configured to use your mirror (as we covered in the sections above).

You will need to setup cron to continuously download updates from an official mirror. The server will also need to be accessible through HTTP or FTP in order to distribute the updates to client computers.

We cover the step by step instructions to set this up in our tutorial on How to create a Ubuntu repository server.

Closing Thoughts

In this tutorial, we saw how to determine and change Ubuntu download mirrors for our system. This should result in faster download speeds when installing updates or new software, but usually does not need to be performed since Ubuntu is supposed to determine the fastest mirror automatically.