apt: autoselect best mirror

3 views
ApiAutomationLinuxProgrammingPythonSecurityTool

We're in 2018 and some nice guy wrote an awesome python script which autoselects the best mirror based on the country you provide and the latency to the servers AND prints you a 'sources.list'. You can simply take this new list and replace the one in '/etc/apt' with it as it's an exact replica except for the updated hostnames.

To install the tool called 'apt-select' you first need PIP the python package manager:

$ apt install python-pip
# or
$ apt install python3-pip

Once installed, run the following command to get the top 5 fastest servers near you. Replace "DE" with your country:

$ apt-select -C DE -t 5 -m up-to-date -c
# -C Country
# -t Top
# -m minimum-update  
# -c choose from top and create sources.list

Simply overwrite your current sources.list with this one:

$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
$ sudo mv source.list /etc/apt/sources.list

Now refresh your cache from your new mirror:

$ sudo apt update
Old Article: To speed up package downloads we can add the following to our sources.list and apt will automatically find the fastest mirror for us. Note: If youre running a different version of Ubuntu replace 'xenial' with your distributions codename. (DISTRIB_CODENAME in /etc/lsb_release) The following command automates this:
sed -i.bak 's/.*xenial.*/deb mirror:\/\/mirrors.ubuntu.com\/mirrors.txt xenial main restricted universe multiverse\ndeb mirror:\/\/mirrors.ubuntu.com\/mirrors.txt xenial-updates main restricted universe multiverse\ndeb mirror:\/\/mirrors.ubuntu.com\/mirrors.txt xenial-backports main restricted universe multiverse\ndeb mirror:\/\/mirrors.ubuntu.com\/mirrors.txt xenial-security main restricted universe multiverse/' /etc/apt/sources.list
Then update the repository cache using apt update.
Legacy Method
bd5e475