188

When I do upgrade it gets stuck here:

user@plato:~# sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  bind9-host coreutils cpio curl dnsutils libbind9-90 libc-bin libc-dev-bin
  libc6 libc6-dev libcgmanager0 libcurl3 libcurl3-gnutls libdns100
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libisc95 libisccc90
  libisccfg90 libjasper1 liblwres90 libplymouth2 libsepol1 libssl-dev
  libssl-doc libssl1.0.0 linux-libc-dev mime-support multiarch-support ntp
  ntpdate openssl plymouth plymouth-theme-ubuntu-text python3-distupgrade
  ubuntu-release-upgrader-core unzip
39 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.0 MB of archives.
After this operation, 12.3 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
0% [Connecting to us.archive.ubuntu.com (2001:67c:1562::15)] ░

When I do update it gets stuck here:

user@plato:~# apt-get update
0% [Connecting to us.archive.ubuntu.com (2001:67c:1562::14)] [Connecting to sec░

I'm able to ping us.archive.ubuntu.com just fine:

user@plato:~# ping us.archive.ubuntu.com
PING us.archive.ubuntu.com (91.189.91.23) 56(84) bytes of data.
64 bytes from economy.canonical.com (91.189.91.23): icmp_seq=1 ttl=54 time=81.5 ms
64 bytes from economy.canonical.com (91.189.91.23): icmp_seq=2 ttl=54 time=81.5 ms
64 bytes from economy.canonical.com (91.189.91.23): icmp_seq=3 ttl=54 time=81.5 ms
64 bytes from economy.canonical.com (91.189.91.23): icmp_seq=4 ttl=54 time=81.4 ms
^C
--- us.archive.ubuntu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 81.425/81.528/81.582/0.355 ms

What can i do to fix this?


What I have tried so far.

I've tried following directions on this blog: http://nickescobedo.com/719/ubuntu-apt-get-hangs-at-0

To force apt-get to use IPv4 exclusively

  • Create a file in /etc/apt/apt.conf.d/99force-ipv4
  • Add this line to newly created file Acquire::ForceIPv4 false;
  • Apt-get will now use IPv4 exclusively
Arian Faurtosh
  • 6,099
  • 4
  • 16
  • 15
  • None of the answers worked for me: my problem was my Windows host firewall blocking my Ubuntu guest running in Virtualbox. – drodsou Jan 02 '18 at 20:10
  • None of these answers worked for me. I restarted my virtual machine and it works now. – kilojoules Apr 25 '18 at 18:33

4 Answers4

341

I figured out how to get apt-get to work again.

Edit gai.conf:

sudo vim /etc/gai.conf

change line ~54 to uncomment the following:

precedence ::ffff:0:0/96  100

write and quit:

:wq

CAUTION

Look out line 50 which looks almost identical:

precedence ::ffff:0:0/96  10

This is the wrong line. Go ~4 lines down and you'll find the correct line to uncomment because it ends with 100 instead of 10

Arian Faurtosh
  • 6,099
  • 4
  • 16
  • 15
  • 2
    Thank you for posting your solution. I was having the same issue and this fixed it. – bradym Jan 21 '15 at 07:00
  • 60
    How on Earth did you figure this out? This suddenly started happening to me on one of my servers and this fixed it. – Brian Neal Jan 25 '15 at 21:11
  • 1
    When this happened to me, I thought I'll need an eternity to figure what is going on. Got this solution as first hit and directly solved it....less than 5 minutes! Still would like to know why this happened in the first place, though. (The solution gives some hints to the cause, but not much) – mikuszefski Mar 22 '15 at 08:08
  • It just happened to me after an update from the software center. Something must have changed it. Totally appreciate the answer, +1 for saving me hours of pain. – Ron Thompson Apr 09 '15 at 20:41
  • Huge thank you, this saved me hours of contacting support and pain. – Joehot200 Jun 05 '15 at 12:37
  • How is it even possible that this happens? I even did a clean Ubuntu install when this happened. – Daniel Jun 16 '15 at 08:27
  • 4
    What is going on here? Care to elaborate why this fix works? – four43 Jun 16 '15 at 20:35
  • 61
    Problem: ISPs are starting to setup an internal IPv6 network in preparation for eventually connecting to the IPv6 internet. As a result, servers in this network now try to connect to .ubuntu.com via its IPv6 address by default when running apt-get. Solution:* uncommenting precedence ::ffff:0:0/96 100 allows requests to prefer IPv4 – Arian Faurtosh Jun 16 '15 at 22:19
  • 8
    FIXED! This is definitely the right fix for this issue. But for anyone that comes across this fix make sure you DO NOT do what I did. I uncommented precedence ::ffff:0:0/96 10 and I had to go back in to the file and comment that line again and then uncomment the correct line which is precedence ::ffff:0:0/96 100 – dtigue Aug 06 '15 at 17:46
  • Nothing better than a magic solution that works as the first Google hit. – Daniel Feb 18 '16 at 04:00
  • THANK YOU SO MUCH! I was wondering why I couldn't update any packages over my phone's tethered internet connection. I wonder how long it will take until Verizon fixes their IPv6? – Aaron Franke Mar 31 '16 at 03:43
  • In addition to the precedence fix, I had to append dns-nameservers 8.8.4.4 8.8.8.8 to the end of /etc/network/interfaces. http://askubuntu.com/questions/766131/set-static-ip-ubuntu-16-04. My ISP is monkeybrains.net. – BSalita Aug 22 '16 at 23:35
  • This did not work for me, this did: http://askubuntu.com/a/759540/4246 – Gauthier Oct 30 '16 at 21:23
  • 1
    Classic. I wish the ISPs wouldn't roll out IPv6 until they have it really working. I had to disable IPv6 on my computer because my home Comcast connection had issues with routing to Google and Facebook. – sudo Feb 21 '17 at 19:02
  • Is there a link to some extended explanation about why this happened? – mbigras Feb 22 '17 at 22:20
  • 1
    Man, you just solved me sooo many issues:D – Adrians Netlis Mar 12 '17 at 21:52
  • You, sir, are a genius. – e18r May 07 '17 at 14:47
  • This fix worked for me, then I saw the comment about home internet and realized that google and only google takes forever to connect as well. Checked facebook and it has the same problem so I disabled IPv6 (see link if you need to do the same) and now they work great. Why does this only create problems for these sites? https://askubuntu.com/questions/440649/how-to-disable-ipv6-in-ubuntu-14-04 – Michael May 26 '17 at 18:13
  • I solved this by changing all sources in /etc/apt/sources.list to https. You'll need apt-transport-https first and to use a mirror that supports https (i.e. deb https://ubuntu.osuosl.org/ubuntu/ xenial main restricted). – crizCraig Nov 17 '17 at 23:14
  • Wow...thanks for the solution. Works like a charm – Parag Jadhav Aug 11 '18 at 09:53
  • Thank you! This also solved my issue. Have a local server in my house as someone pointed out above this is an IPS issue/feature... – gregwinn Dec 14 '19 at 22:09
  • WTF ! What sorcery is this !!! Worked like magic . Upvoted ! – Joy Mar 12 '20 at 05:01
  • ???? ARE YOU A WIZARD? – desertkun Dec 24 '20 at 22:07
19

It's better to disable the IPV6 before you update and upgrade.

  1. Open Terminal

  2. Enter sudo -H gedit /etc/sysctl.conf and open the configuration file and add the following lines at the end

    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1 
    net.ipv6.conf.lo.disable_ipv6 = 1 
    
  3. After that run

    cat /proc/sys/net/ipv6/conf/all/disable_ipv6 
    

    If it reports ‘1′ means you have disabled IPV6.

    If it reports ‘0‘ then please follow Step 4 and Step 5.

  4. Type command sudo sysctl -p. You will see this in terminal.

    net.ipv6.conf.all.disable_ipv6 = 1 
    net.ipv6.conf.default.disable_ipv6 = 1 
    net.ipv6.conf.lo.disable_ipv6 = 1 
    
  5. Repeat above “Step 3” and it will now report 1.

muru
  • 197,895
  • 55
  • 485
  • 740
9

None of the IPv6 fixes worked for me. Possibly I have the same symptom with a different cause. My workaround was to switch to a different archive by doing a search and replace in sources.list, e.g.:

sudo vim /etc/apt/sources.list

And then:

:%s/us\.archive/de\.archive/g
:wq

This at least allows me to get back to work until I figure out the real problem.

3

What worked for me was to switch my VirtualBox Network settings for my Ubuntu guest to "NAT" from "Bridged Adapter".

user994165
  • 225
  • 4
  • 11
  • 2
    Yes, this is bound to work. But, why doesn't it work over 'Bridged Adapter'. I am able to do everything with 'Bridged Adapter' except apt-get update. – soufrk Mar 13 '18 at 11:47