Apt update slow? Try this fix

On a cloud instance with a slow disk, running the dreaded apt update && apt upgrade could take an eternity. But what if I tell you it may actually not be a disk IOPS issue?

Larger cloud service providers like Microsoft, Google, Amazon, Linode, and Alibaba operate and host their own update servers. When you perform package updates, you are actually getting intranet speeds. The problem arises when your provider gives you an OS image that is set to update using US servers for your Singapore VPS. Fortunately, this can be easily fixed.

You can, of course, head down to the official LaunchPad mirror listing or use the country-code method. But there exists a far more scientific way.

First, you’ll need a tool called netselect, which automatically pulls the Ubuntu mirror list and benchmark them based on their latency to your VPS’ location. This package is not shipped with Ubuntu by default, so you will need to install it manually:

wget http://ftp.au.debian.org/debian/pool/main/n/netselect/netselect_0.3.ds1-28+b1_amd64.deb
dpkg -i netselect_0.3.ds1-28+b1_amd64.deb

The following command will call netselect to benchmark the top 20 hosts from the mirror list:

netselect -s 20 -t 40 $(wget -qO - http://mirrors.ubuntu.com/mirrors.txt)

In my example, I get the following results:

     1 http://mirror.0x.sg/ubuntu/
   441 http://archive.ubuntu.com/ubuntu/
   442 http://archive.ubuntu.com/ubuntu/
   446 http://archive.ubuntu.com/ubuntu/
   450 http://archive.ubuntu.com/ubuntu/
   467 http://archive.ubuntu.com/ubuntu/
   469 http://archive.ubuntu.com/ubuntu/
 Only found  7 hosts out of 20 requested.

What that, I have established that in my location, mirror.0x.sg is going to be fastest server for apt. I’m going to use this information to update the mirror list:

nano /etc/apt/sources.list

Use Ctrl-\ to search for the existing server domain (e.g. us.archive.ubuntu.com) and then replace it with mirror.0x.sg. When prompted, apply this Replacement for all entries.

Save the sources.list file and blast away with apt update && apt upgrade -y 🙂


Comments

Leave a Reply