16.04 apt-get update hangs [duplicate]

Both apt-get update and upgrade hang:

sudo apt-get update
[sudo] password for xxx: 
0% [Connecting to archive.ubuntu.com (2001:67c:1360:8001::17)]

I'm able to ping archive.ubuntu.com:

ping archive.ubuntu.com
PING archive.ubuntu.com (91.189.88.162) 56(84) bytes of data.
64 bytes from yukinko.canonical.com (91.189.88.162): icmp_seq=1 ttl=50 time=42.2 ms
64 bytes from yukinko.canonical.com (91.189.88.162): icmp_seq=2 ttl=50 time=42.1 ms
64 bytes from yukinko.canonical.com (91.189.88.162): icmp_seq=3 ttl=50 time=42.1 ms
^C
--- archive.ubuntu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 42.169/42.206/42.265/0.240 ms

I checked this question, and I don't think its the same issue.

Any tips for investigating this further?


Solution 1:

From your output it seems to me that it's a IPv6 problem, so we should force apt to use IPv4 instead.

If we search apt.conf (5) manual for IPv4 we will find:

ForceIPv4:
When downloading, force to use only the IPv4 protocol.

To enable this option we should create a file within:

/etc/apt/apt.conf.d/

the name can be anything for something relative we use 99force-ipv4, the number is the priority of config files within this directory.

Then add the below command to this file and save it:

Acquire::ForceIPv4 "true";

Then try updating your source again:

sudo apt update

Not sure of the cause of problem, however I think your university is running an internal IPv6 network; so apt is trying to connect with IPv6 to its mirrors, and there may be some incompatibility. I just tried forcing apt to use IPv4 and it worked.

Short instruction:

Also we can use echo and tee to write this config down with one command (from here):

echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4