apt: autoselect best mirror
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. To install it use: 'apt install python-pip' or 'apt install python3-pip'. Once installed check the run the following command to get the top 5 fastest servers near you. Of course replace "DE" which 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
'
There you go! Simply overwrite your current sources.list with this one:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak; and 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 ' deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-backports main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted universe multiverse ' > /etc/apt/sources.list
Then update the repository cache using
apt update
.