How to fix the slow apt-get update issue on Ubuntu/Debian Server¶
While updating or installing new packages in Ubuntu/Debian server we often experienced slow downloading speed even while our network connection is running fine. So when you run command # apt-get update, you see a slow download speed for packages. This just means you’re connected to a Source Mirror server that’s really busy. Some users complain that nothing happens or they are not getting any updates at all. Some got different issues like update stuck is the header and doesn’t move or resolve any further.
Usually slow speed on Ubuntu/Debian server update & upgrade is due to these several issues:
- Mirrors issue
- Name Servers issue
- Repositories issue
- Unknown issues
In order to fix apt-get update, you need to check a few points:
- Check if you have the right source repositories is your /etc/apt/sources.list file
- Remove unwanted or unsupported source repositories.
- Clean apt-get cache.
- Choose a fast DNS server.
1. Fixing Name Server’s issue
Clear apt-get cache:
# apt-get clean
2. 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 220.127.116.11 nameserver 18.104.22.168
Or CloudFlare Name Server
nameserver 22.214.171.124 nameserver 126.96.36.199
Now save and close the file.
3. 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.
1. Change HTTP to repo in sources.list file
You can check and go with the official LaunchPad mirror 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.
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.