Networking

How to fix the slow apt-get update issue on Linux machines

If apt-get is slowing to a crawl or even stopping, read about the IPv6 fix that will keep your Linux server and desktop updates running smoothly.

aptgethero.jpg
Image: Jack Wallen

Over the last month, an odd issue tripped up Linux distributions that use apt-get for updating and upgrading. Upon issuing the command sudo apt-get update, the process would stall when connecting with any of the default repositories or slow to a crawl when downloading headers during the update process.

After much troubleshooting and chasing down the wrong rabbit holes (such as DNS, cache, and gateway issues), I finally discovered the problem. You may be surprised at the solution.

SEE: System Monitoring Policy (Tech Pro Research)

The first failed fix

When this happened to me previously, the solution was to allow Software & Updates to download from the best server. To do this, you'd open Software & Updates, click the Download from the drop-down and select Other.

In the resulting window (Figure A), click Select Best Server and allow the system to set the ideal server for your location. Once that completes, click Choose Server, enter your sudo password, and click Authenticate. Once the process completes, click Close and when prompted click Reload. You're finished.

Figure A

Figure A

Selecting the best server for Elementary OS Loki updates.

Under normal circumstances, this fixes the problem; this time it was a no-go.

Onward and forward.

The right fix

It took quite some time to figure this one out, but the problem lies in IPv6. With IPv6 enabled, the recent network stack seems to stumble at times, especially when attempting to update with apt.

Unfortunately, simply disabling IPv6 in your network device settings isn't enough—you have to completely disable IPv6 systemwide, and then apt works like a champ.

How do you disable IPv6 systemwide? Simple. Open the /etc/sysctl.conf file with the command sudo nano /etc/sysctl.conf and add the following to the bottom of the file:

net.ipv6.conf.all.disable_ipv6 = 1
​net.ipv6.conf.default.disable_ipv6 = 1
​net.ipv6.conf.lo.disable_ipv6 = 1

Save and close the file. Next, restart networking with the command sudo service networking restart. When that command completes, re-run sudo apt-get update, and you should see the process work as expected.

An unexpected bonus

After disabling IPv6 globally, a number of other networking services started working much more smoothly. Web browsing was more reliable (no more random pauses with Google Apps or Facebook); Spotify stopped inexplicably freezing; and downloads were significantly faster. This fix is a must-do—at least until the issues with IPv6 are sorted out.

Do this now

This fix doesn't harm the network or any other stack on your system. The only problem you might face is if you use IPv6 as your primary networking scheme—at which point, you probably aren't having issues with apt-get anyway.

I highly recommend this solution. You'll enjoy a more robust and reliable networking experience on your Linux machine.

Also see

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks