Skip to main content

Fix slow apt-get update issue on Ubuntu/Debian Server

While updating or installing new packages in Ubuntu/Debian servers, slow download speeds may occur even when the network connection is running smoothly. If you run the command # apt-get update, and experience slow download speeds for packages, it likely means you’re connected to a busy Source Mirror server. Some users report no updates happening, updates stuck at the header, or other issues.

Slow speed on Ubuntu/Debian server updates & upgrades can be due to:

  • Mirror issues
  • Name server issues
  • Repository issues
  • Other unknown issues

In order to fix apt-get update, check the following:

  • Verify if the correct source repositories are in your /etc/apt/sources.list file.
  • Remove unwanted or unsupported source repositories.
  • Clean the apt-get cache.
  • Choose a fast DNS server.

Method 1: Fixing Name Server Issues

  1. Clear apt-get cache:
   apt-get clean
  1. Choose a proper DNS server**

Edit resolv.conf file:

vi /etc/resolv.conf

Enter Google/CloudFlare DNS nameservers

The following two are Google DNS, admittedly, if Google is broken, we all think the Internet is broken. Hence the reason of using Google DNS. You can choose other DNS servers like CloudFlare if you want that are fast and reliable.

nameserver 8.8.8.8
nameserver 8.8.4.4

Or CloudFlare Name Server

nameserver 1.1.1.1
nameserver 1.0.0.1

Now save and close the file.

  1. Test your changes**

Let's put our changes to the test.

Do an apt-get update

apt-get update

Do and upgrade

apt-get upgrade

Finally, do a distribution upgrade

apt-get dist-upgrade

Your download speed should be much greater than what you were getting earlier.

Method 2

1. Change HTTP to repo in sources.list file

You can check and go with the official LaunchPad mirror <https://launchpad.net/ubuntu/+archivemirrors>_ listing or use the country-code method. But we have a much more scientific method.

First, you will need to install a tool called netselect, which automatically pulls the Ubuntu/Debian source mirror list and benchmark them based on their latency to your Server location. This package is not shipped with Ubuntu/Debian by default, so you have 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 source hosts from the source mirror list:

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

For example, we have established that in our location, repo.extreme-ix.org is going to be fastest mirror server for apt. We are going to use this information to update the mirror list:

vi /etc/apt/sources.list

Next, search for the existing server domain (e.g. us.archive.ubuntu.com) and then replace it with repo.extreme-ix.org. At the prompt, perform this replacement for all entries.

Save the sources.list file and run command # apt update && apt upgrade -y to update repo source and server packages.

Method 3

Transport HTTP mirrors to HTTPS mirrors in sources.list file

1. Transport source to https.

Transport source from http to https. Open the terminal and run the following command to install apt-transport-https package.

apt install apt-transport-https

2. Edit resources

Just change HTTP to HTTPS and Save the sources.list file and run command # apt update && apt upgrade -y to update repo source and server packages.