Introduction

The first important thing to do after installing a new Ubuntu operating system is to choose the best and fastest APT file mirror. In this brief guide, I have listed how to find the best mirror in the Ubuntu APT repository based on download speed.

Mirrors are not always the closest to your location, but they offer the best possible download rate and update status.

Prerequisites

  • A single instance of VPS with the Centos 8 template (1 GB of RAM will work fine)

Find Best Ubuntu APT Repository Mirror

Before moving further, it is highly recommended to backup the existing sources.list file:

$

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

Now let us find out the best APT archive mirror.

To search for the best mirror, we will use the Apt-select

The tool mentioned above are written in Python. Therefore, they can be installed using the Pip package manager. If you have not yet installed Pip, install it using the command:

$

sudo apt install python3-pip

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

Make sure you have installed Pip and run the following command to install apt-select:

$

pip3 install apt-select

Now run the following command to find top apt mirror for a given country:

$

apt-select --country BR

Sample output:

Getting list of mirrors...done. Testing latency to mirror(s) [10/10] 100% Getting list of launchpad URLs...done. Looking up 1 status(es) 1 ubuntu.letscloud.io Latency: 0.45 ms Org: LetsCloud Status: Up to date Speed: 1 Gbps Selecting mirror https://ubuntu.letscloud.io/ubuntu/ ... New config file saved to /root/sources.list

The above command returns only one top mirror from Brazil 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

You 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 /root/sources.list

Display mirrors based on status

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

  • up-to-date,
  • one-day-behind,
  • two-days-behind,
  • one-week-behind, unknown. By default, apt-select will return up-to-date mirrors.

The following commands returns 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 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 top 3 mirrors by latency, excluding the statuses, use -p flag:

$

apt-select -t 3 -p

Choose mirrors from a list This command allows you to choose one mirror from top 3 US mirrors and generates the sources.list.

$

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

For help, run:

$

apt-select --help

Refer the Apt-select GitHub repository for more details:

Read more about: Operating SystemUbuntu