How to fix apt timing out on a Raspberry Pi

November 6th, 2024

On some corporate networks I’ve run into a brick wall when using apt update on a Raspberry Pi. The first couple of repositories connect successfully. Then it usually gets up to archive.raspberrypi.com and hangs and times out.

Apt defaults to IPv6 when it is available, and in some cases it just does not seem to play nicely. The solution - force IPv4 instead.

You can do this via the -o flag when running the command:

sudo apt -o Acquire::ForceIPv4=true update

Or you can edit the apt configuration and add a line to make IPv4 permanent:

sudo nano /etc/apt/apt.conf.d/99force-ipv4

Add this line:

Acquire::ForceIPv4 "true";

If you found this useful, I have started collating notes on working with the Raspberry Pi in a central place.