Speed Up Your apt update: Troubleshooting Slow Performance
If you're experiencing slow performance with the apt update command on a Linux VPS with Ubuntu 20.04, there are several potential causes and corresponding solutions you can investigate:
Note: If you login as user, run this command to login as root : sudo su
Geographically Distant Mirrors
Cause: The default repository mirrors may be geographically distant from your location.
Solution: Change the mirror to my.archive.ubuntu.com by running :
Local Cache Issues
Cause: Corrupted or outdated cache can affect apt update.
Solution: Clear the local cache by running:
DNS Issues
Cause: Slow DNS response times can slow down repository access.
Solution: Change your DNS settings to use faster public DNS servers, such as Google DNS (8.8.8.8, 8.8.4.4) or Cloudflare DNS (1.1.1.1, 1.0.0.1).
Update to:
Google
Cloudflare
Check current DNS server :
Proxy Server
Cause: If you are behind a proxy, the proxy server might be causing delays.
Solution: Check your proxy settings and ensure they are correctly configured. You can also try bypassing the proxy to see if it improves speed.
Firewall and Network Configuration
Cause: Network firewalls or misconfigurations can slow down or block connections.
Solution: Check firewall rules and network configurations to ensure they're not the bottleneck. Consult with your network administrator if you're in a managed environment.
Solution: Ubuntu usually preinstalled with ufw firewall.
Check the detailed status of the UFW service:
sudo ufw status verbose
Stop and disable the UFW service:
sudo ufw disable
Run apt update at Different Times of Day: Sometimes server load varies throughout the day. Running updates during off-peak hours might be faster.
Use Parallel Downloads: Enable parallel downloads in APT for faster updates.
Example /etc/apt/sources.list with Updated Mirrors
Here's an example of how your /etc/apt/sources.list might look after updating to a country-specific mirror:
By addressing these potential issues, you can often significantly improve the performance of the apt update command.
Common Causes and Solutions
Note: If you login as user, run this command to login as root : sudo su
Geographically Distant Mirrors
Cause: The default repository mirrors may be geographically distant from your location.
Solution: Change the mirror to my.archive.ubuntu.com by running :
sed -i -e 's/ru.archive.ubuntu.com/my.archive.ubuntu.com/g' /etc/apt/sources.list
Local Cache Issues
Cause: Corrupted or outdated cache can affect apt update.
Solution: Clear the local cache by running:
sudo rm -rf /var/lib/apt/lists/*
sudo apt update
DNS Issues
Cause: Slow DNS response times can slow down repository access.
Solution: Change your DNS settings to use faster public DNS servers, such as Google DNS (8.8.8.8, 8.8.4.4) or Cloudflare DNS (1.1.1.1, 1.0.0.1).
sudo nano /etc/resolv.conf
Update to:
nameserver 8.8.8.8
nameserver 8.8.4.4
Cloudflare
nameserver 1.1.1.1
nameserver 1.0.0.1
Check current DNS server :
`systemd-resolve --status
Proxy Server
Cause: If you are behind a proxy, the proxy server might be causing delays.
Solution: Check your proxy settings and ensure they are correctly configured. You can also try bypassing the proxy to see if it improves speed.
Firewall and Network Configuration
Cause: Network firewalls or misconfigurations can slow down or block connections.
Solution: Check firewall rules and network configurations to ensure they're not the bottleneck. Consult with your network administrator if you're in a managed environment.
Solution: Ubuntu usually preinstalled with ufw firewall.
Check the detailed status of the UFW service:
sudo ufw status verbose
Stop and disable the UFW service:
sudo ufw disable
Additional Tips
Run apt update at Different Times of Day: Sometimes server load varies throughout the day. Running updates during off-peak hours might be faster.
Use Parallel Downloads: Enable parallel downloads in APT for faster updates.
echo 'APT::Acquire::Retries "3";' | sudo tee -a /etc/apt/apt.conf.d/80-retries
echo 'Acquire::Queue-Mode "access";' | sudo tee -a /etc/apt/apt.conf.d/80-queue-mode
Example /etc/apt/sources.list with Updated Mirrors
Here's an example of how your /etc/apt/sources.list might look after updating to a country-specific mirror:
deb http://my.archive.ubuntu.com/ubuntu/ focal main restricted
deb http://my.archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://my.archive.ubuntu.com/ubuntu/ focal universe
deb http://my.archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://my.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://my.archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://my.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
By addressing these potential issues, you can often significantly improve the performance of the apt update command.
Updated on: 28/05/2024
Thank you!