How to choose fastest apt mirrors on Ubuntu?

While updating or downloading applications the download speed can sometimes be really bad. So it is important to select the nearest mirrors of ubuntu so you can enjoy the fastest download speeds. Also some cloud providers like Hetzner, Google Cloud add their own mirrors to the sources list and we face problems while installing many popular programs like docker, OpenJDK, etc.

There are times when we try to do sudo apt install or sudo apt install default-jre and we get the following error –

sudo apt install
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package
E: Couldn't find any package by glob ''
root@ubuntu-2gb-hel1-1:~# sudo apt install default-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package default-jre

This happens when the repository mirrors which are added in the server’s sources.list file does not contain these applications and can be fixed by simply changing to the appropriate sources.

Adding the official ubuntu mirrors to the sources.list file fixes this problem and we are able to install the programs.

How to select the fastest mirrors on Ubuntu?

There are three different ways you can use to find the fastest and nearest Ubuntu mirrorsĀ  –

1. Use country code

If you are in the United States or Canada then you can just put ‘us ‘ or ‘ca’ in front of the URLs. In this way, you will connect to your country’s official Ubuntu repository mirror.

If you are in the United States just add us in front of all the URLs present in the sources.list file

deb focal main restricted

Or if you are in Canada simply add ca in front of all the URLs

deb focal main restricted

But this is always not the best solution because depending on your ISP, they might have different peering arrangements which can limit your download speeds.

2. Select mirrors manually

The next best solution is to manually find the best available mirrors and then add those to your sources file.

Type the following command on the command line –

$ wget -qO -

Then the nearest and fastest mirrors will be displayed. copy those and paste them in the sources file iin the correct format.

$ wget -qO -

3. Use mirror protocol

Ubuntu supports are mirror protocol in the sources.list file which will automatically connect you to the nearest mirror. Replace the current source entry

deb focal main restricted


deb mirror:// focal main restricted

Replace all the other entries in the file similarly in proper format as it was before.

How to update mirrors on the sources.txt file?

Follow these steps in order to update the sources.txt file –

  • Log into your Linux VM as the root user.
  • Open the sources.list file with nano.
  • Now add or edit the sources in any way you want from the above three ways.
  • Remember to add the sources in proper formats as it was already in the file. Also, remember to add the correct version name of Ubuntu which is currently installed. Here is a table with the names of the Ubuntu versions.
Ubuntu 14.04Trusty Tahr
Ubuntu 16.04Xenial Xerus
Ubuntu 18.04Bionic Beaver
Ubuntu 20.04Focal Fossa
Ubuntu 20.10Groovy Gorilla
Ubuntu 21.04Hirsute Hippo
  • Save that file by pressing CTRL+X simultaneously and then ‘Y’.
Update the URLs of the apt repositories in the proper format.
  • Now update
sudo apt update
  • You have now successfully updated the mirrors list.
How to choose fastest apt mirrors on Ubuntu?
Article Name
How to choose fastest apt mirrors on Ubuntu?
Learn how to locate the nearest Ubuntu repositories and add them to your sources.list file.

Leave a Comment