Bobcares

Best Ubuntu APT Repository Mirror – How to find it

by | Apr 5, 2021

Wondering how to find the best Ubuntu APT Repository Mirror? We can help you.

After installing a fresh Ubuntu OS it is important to choose the best and fastest APT archive mirror.

Here at Bobcares, we handle requests from our customers with Ubuntu servers to add the best Ubuntu APT repository mirror as a part of our Server Management Services.

Today let’s see how our Support Engineers choose the best APT mirror for our customers.

Why do we need the Best Ubuntu APT Repository Mirror

If our system is connected to the Internet at the time of installation, the installer will automatically select the nearest mirror depending on our location and ISP.

However, if the Internet is not available, the Main repository will be selected. If we live outside of the US, installing packages from the Main repository might be painfully slow.

This is why it is a must to choose the best and also the nearest mirror for our Ubuntu system.

Methods to find best Ubuntu APT repository Mirror

Now we will see the methods that our Support Techs follow to find the best Ubuntu repository Mirror.

Before moving further, we need to take the backup of the existing sources.list file using the following command:

$ sudo cp /etc/apt/sources.list{,.backup}

We can find the best mirror using GUI and CLI.

The graphical way:

1. First, open the “Software & updates” window.

2. Then choose “Other” in the “Download from” drop-down box and then choose the “Select Best Server” option.

3. Once the best mirror is found, click the “Choose Server” option.

4. After that Close the Software & Updates window.

5. And click the “Reload” button to update the repository lists. Now our sources.list is automatically updated with the best and fastest Ubuntu repository mirror URLs.

The command-line way:

There are many command-line tools available to find the best APT mirrors based on download speed.

We will use two of the following tools:

1. Apt-select
2. Apt-smart

Since the tools are written in Python we will be using Pip package manager.

If we have not installed Pip yet, install it using the following command:

$ sudo apt install python3-pip

1. Find Best Ubuntu APT Repository Mirror Using Apt-select

Apt-select is a command-line tool to find a fast and up-to-date Ubuntu archive mirror. It generates sources.list file for each country or depending upon top-ranked mirrors by download rate.

First, we can run the following command to find the top apt-mirror for a given country:

$ apt-select --country IN

or

$ apt-select -C IN

Sample output:

Getting list of mirrors...done.
Testing latency to mirror(s)
[7/8] 87% connection to ubuntu.mirror.snu.edu.in: timed out
[8/8] 100%
Getting list of launchpad URLs...done.
Looking up 1 status(es)
1. ubuntu-archive.mirrors.estointernet.in
Latency: 85.85 ms
Org: Esto Internet
Status: Up to date
Speed: 10 Gbps
Selecting mirror http://ubuntu-archive.mirrors.estointernet.in/ ...
New config file saved to /home/ostechnix/sources.list

The above command returns only one top mirror from India and generate a new sources.list and save it in the current directory.

If no country code is provided, the US mirrors will be fetched by default.

Display top N mirrors

We can also generate sources.list from top N mirrors using -t flag.

By default, it displays only one top mirror.

$ apt-select -t 3

Sample output:

WARNING: no country code provided. defaulting to US.
Getting list of mirrors...done.
Testing latency to mirror(s)
[85/85] 100%
Getting list of launchpad URLs...done.
Looking up 3 status(es)
[3/3] 100%
1. la-mirrors.evowise.com
Latency: 40.64 ms
Org: Evowise.com
Status: Up to date
Speed: 10 Gbps
2. mirrors.xtom.com
Latency: 246.64 ms
Org: xTom
Status: Up to date
Speed: 20 Gbps
3. mirrors.advancedhosters.com
Latency: 253.92 ms
Org: AdvancedHosters
Status: Up to date
Speed: 2 Gbps
Selecting mirror http://la-mirrors.evowise.com/ubuntu/ ...
New config file saved to /home/ostechnix/sources.list
Display mirrors based on status

Apt-select can display results on mirrors’ status with -m flag. The choices are:

  1. up-to-date
  2. one-day-behind
  3. two-days-behind
  4. one-week-behind
  5. unknown

By default, apt-select will return up-to-date mirrors.

The following commands return mirrors that are one week behind:

$ apt-select -m one-week-behind

We can combine multiple options and generate sources.list file. For example, the following command will return the top 3 mirrors, including those last updated a week ago:

$ apt-select -c -t 3 -m one-week-behind
Rank mirrors by latency

To list the top 3 mirrors by latency, excluding the statuses, use the following command with -p flag:

$ apt-select -t 3 -p
Choose mirrors from a list

The following command allows to choose one mirror from the top 3 US mirrors and generates the sources.list.

$ apt-select --choose -t 5 --country US

or

$ apt-select -c -t 5 -C US
Update our system’s sources.list file

After generating the sources.list file as per our requirement, we can replace the original one (/etc/apt/sources.list) with the new one.

We can do this using the following commands:

$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
$ sudo mv sources.list /etc/apt/

2. Find Best Ubuntu APT Repository Mirror Using Apt-smart

Apt-smart is yet another command-line tool written in Python. It helps to find APT mirrors that provide the best download rate for our location.

Furthermore, it discovers mirrors by bandwidth and their status. Another notable feature of Apt-smart is it will automatically switch to any other different mirrors when the current mirror is being updated.

Install Apt-smart in Ubuntu

First, we have to ensure that Pip package manager is available:

After that run the following commands one by one to install Apt-smart:

$ pip3 install --user apt-smart
$ echo "export PATH=\$(python3 -c 'import site; print(site.USER_BASE + \"/bin\")'):\$PATH" >> ~/.bashrc
$ source ~/.bashrc
Display current mirror’s details

To list the current main mirror in the /etc/apt/sources.list file and display its details in the standard output, we can run the following command:

$ apt-smart --find-current-mirror

or

$ apt-smart -f

Find best mirror

We can discover available mirrors, rank them and choose the best one from the list and display it in the standard output.

Using the following commands we can do this:

$ apt-smart --find-best-mirror

or

$ apt-smart -b

Sample output:

2021-04-02 07:13:41 ubuntuserver apt_smart[1613] INFO Ubuntu 20.04 (focal) is supported (based on known EOL dates).
2021-04-02 07:13:41 ubuntuserver apt_smart[1613] INFO Adding BASE_URL mirror:
2021-04-02 07:13:41 ubuntuserver apt_smart[1613] INFO http://archive.ubuntu.com/ubuntu
2021-04-02 07:13:41 ubuntuserver apt_smart.backends.ubuntu[1613] INFO Identifying fast Ubuntu mirrors using http://mirrors.ubuntu.com/mirrors.txt ..
2021-04-02 07:13:42 ubuntuserver apt_smart.backends.ubuntu[1613] INFO Discovered 8 Ubuntu mirrors in 0.8 seconds.
2021-04-02 07:13:42 ubuntuserver apt_smart[1613] INFO Checking 9 mirrors for availability and performance ..
2021-04-02 07:13:44 ubuntuserver apt_smart[1613] INFO Start retrieving :attr:`base_last_updated` using is_available
2021-04-02 07:13:44 ubuntuserver apt_smart[1613] INFO Checking 8 mirrors for Archive-Update-in-Progress marker ..
2021-04-02 07:13:52 ubuntuserver apt_smart[1613] INFO Finished checking 9 mirrors (took 10.55 seconds).
http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu
List all mirrors based on rank

We can use the following commands for this:

$ apt-smart --list-mirrors

or

$ apt-smart -l
Change mirrors

Once we found the best APT mirror, we can update our /etc/apt/sources.list to use the given mirror.

We can do this using the following command:

$ apt-smart --change-mirror http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu
$ apt-smart -c http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu
Automatically update mirrors

Instead of manually finding and updating the best mirror in Ubuntu, we can let Apt-smart choose the best Apt mirror and automatically update the sources.list with a new one.

We can do this using the following command:

$ apt-smart --auto-change-mirror

[Need assistance? We can help you]

Conclusion

To conclude, we saw how our Support Techs find the best APT mirror on the Ubuntu server.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.