How to select the fastest apt mirror on Ubuntu Linux

The following guide will provide you with some information on how to improve Ubuntu's repository download speed by selecting the closest, that is, possibly fastest mirror relative to your geographical location.

Country Code

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/ xenial main restricted

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/ xenial main restricted

Use mirror protocol

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/ xenial main restricted

to:

deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted

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:

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:

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. The netselect package is not available within Ubuntu's standard repository by default, so we will need to borrow it from Debian stable repository:

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 ):

ARE YOU LOOKING FOR A LINUX JOB?Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.

DO YOU NEED ADDITIONAL HELP?Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:

Comments and Discussions

SUPPORT US

LinuxConfig.org team is determined to provide you with simple to follow Linux tutorials, various tips, tricks and programming guides as well as with GNU/Linux system administration tutorials in general to help you to learn Linux faster and use it with ease.

Donations

Bitcoin (BTC) Address:1PyYJEVtxkokkYtLkRw9BA7Fr4xEAXJn3U

Litecoin (LTC) Address:LXvDNUcdKuh3Svge358rNanXfXMKcPkxCo

Thank You

Write For Us

LinuxConfig is looking for a technical writer(s) geared towards GNU/Linux and FLOSS technologies. Your articles will feature various GNU/Linux configuration tutorials and FLOSS technologies used in combination with GNU/Linux operating system.

When writing your articles you will be expected to be able to keep up with a technological advancement regarding the above mentioned technical area of expertise. You will work independently and be able to produce at minimum 2 technical articles a month.