How to select the fastest apt mirror on Ubuntu Linux - LinuxConfig.org

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.
This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-select-the-fastest-apt-mirror-on-ubuntu-linux

pcolby

Excellent article - very helpful! Thanks :slight_smile:

Once small tip: sed’s substitute command (s) allows you to swap the ‘/’ separator with any other single character. Since URLs often contain ‘/’ chars, its convenient to use a different separator, such as ‘|’. So, you example:

sed -i 's/http:\/\/us.archive.ubuntu.com\/ubuntu\//http:\/\/ubuntu.uberglobalmirror.com\/archive\//' ...

becomes

sed -i 's|http://us.archive.ubuntu.com/ubuntu/|http://ubuntu.uberglobalmirror.com/archive/|' ...

which is just a bit easier, since you don’t have to manually escape the cut-and-pasted URLs :slight_smile:

Also, the in-place argument (-i) accepts a filename suffix to automatically create a backup. So, for example,

sudo sed -i.backup 's...' /etc/apt/sources.list

will automatically creates a file /etc/apt/sources.list.backup, which is a copy of the file prior to sed’s modifications (though I’d probably back it up manually with cp -a beforehand anyway).

Thanks again!

Justin Johnston

Nice article, although it seems netselect doesn’t run on Ubuntu 18.04 yet.

As a work-around, I wrote this one-liner that shows the top 20 fastest mirrors based on ICMP latency using ping.

for mirror in $(wget -qO - mirrors.ubuntu.com/mirrors.txt|sed ‘s/^http:////;s//.$//') ; do echo $(ping -c 1 $mirror|grep "^64 bytes.time="|sed 's/^64 bytes.=//;s/ .$//’) $mirror ; done|sort -n|grep “[1]”|head -n 20


  1. 0-9 ↩︎

Sajeev Ramasamy

when i run the netselect command, i’m getting the following error: netselect: socket: Permission denied. Could anyone help me?

Lubos Rendek -> Sajeev Ramasamy

use sudo command as shown on the above example

Sajeev Ramasamy -> Lubos Rendek

That’s what baffles me. I’m getting the error even when I use sudo

Lubos Rendek → Sajeev Ramasamy

Also have a look here: https://linuxconfig.org/how-to-create-sudo-user-on-ubuntu-18-04-bionic-beaver-linux

Lubos Rendek -> Sajeev Ramasamy

Is you user in sudo group? Run:

$ id whoami

Sajeev Ramasamy -> Lubos Rendek

the user belongs to the sudo group, also i’m trying this in WSL.

Sajeev Ramasamy -> Lubos Rendek

My user belongs to the sudo group, I should also mention that I’m trying this in WSL.

David Orozco

love this approach