86

I have looked at similar questions:

Stuck at 0% [waiting for headers]

apt-get update stuck on "Waiting for Headers" when using Windows XP ICS

However neither one of them answer my problem.

I am running 12.04 AMD64 and have recently started getting an issue that when I update my repos from my connection at home through a terminal, using sudo apt-get update, it takes forever (literally after 2 hours it was at 28%), however when I run from a different location it takes less than 5 minutes to complete.

I have attempted changing which mirror I use but that does not solve the issue. I have also cut down what is in my sources list but this also makes no difference. There are no faults on my ADSL line as I have already contacted my ISP to check this. It also makes no difference if I use a WiFi or network cable connection.

What could be my issue?


A speed test (www.speedtest.net) comes out at about 0.9 Mbps down and 0.42 Mbps up (which is a shade under the advertised line speed), I reside in South Africa and use the UCT LEG server. But I have also tried the other mirrors available in SA....none of them make a difference.

Liam
  • 861
  • 1
  • 6
  • 3
  • 4
    Please report results from http://www.speedtest.com, and tell us your country of residence. – ish Jun 27 '12 at 10:26

12 Answers12

79

I found a solution which helped me here: https://www.kubuntuforums.net/showthread.php?57567-Ubuntu-problems-on-update

You can let apt-get to regenerate lists cache using:

sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update 
Chronos
  • 929
44

This sounds like it may be an issue with third party repos. I know Google's repo takes several minutes to respond here sometimes. If you have third party repos set up, open Update Manager, click Settings, then the "Other Software" tab. Uncheck all checkboxes, then hit close.

Update Manager Update Manager - Other Software

Now, fire up a terminal and use the following command and see if it is any better with the following command:

sudo apt-get update

If it is better, go back and enable each repo and recheck one by one until you find the problem repo.

If that does not work, you can have the update manager select the best main repos to use automatically. To do that, open Update Manager, then click Settings. Select the Ubuntu Software tab, then in the "Download from:" dropdown, select Other...

Update Manager - Ubuntu Software Tab

Now, in the window that pops up, click "Select Best Server"

Update Manager - Choose a Download Server

It will then perform several tests to select the best server for you. Once it is completed, just click Choose Server.

Update Manager - Choose a Download Server

Now, fire up the terminal and check again.

reverendj1
  • 16,045
6

This is mostly because of "MTU size", been having this issue for a while and after some deep inspection i have found out that my isp has an mtu size of 1440 while the default for eth interface is 1500.

to know the max mtu size please see here.

to set your mtu packet size you can either use the network connection option from the network icon or use terminal as in this link.

Mark Kirby
  • 18,529
  • 19
  • 78
  • 114
  • 1
    Your first and second links are both coded to point to the second site. I found the information at the dslreports.com site to be descriptive and helpful. Unfortunately the information at the cyberciti.biz site may be a bit outdated, and (at least here) doesn't address the problem very well. – Tommy Trussell Feb 10 '15 at 07:20
2

Open terminal and type:

cd /etc/apt/apt.conf.d/

Now create a new file sudo nano 99self and type:

Acquire::http::Pipeline-Depth "0";
  • 5
    Welcome to Askubuntu! Could you develop your answer to explain in more depth why and how your solution works? – Marc Vanhoomissen Mar 24 '18 at 16:33
  • According to the (5) apt.conf manpage: The setting Acquire::http::Pipeline-Depth can be used to enable HTTP pipelining (RFC 2616 section 8.1.2.2) which can be beneficial e.g. on high-latency connections. It specifies how many requests are sent in a pipeline. Previous APT versions had a default of 10 for this setting, but the default value is now 0 (= disabled) to avoid problems with the ever-growing amount of webservers and proxies which choose to not conform to the HTTP/1.1 specification. – roens Jan 28 '23 at 22:03
2

This issue can also occur if your DNS servers aren't functioning correctly (or if you've configured the wrong DNS servers).

I ran cat /etc/resolv.conf and realised I'd mistyped the DNS server. Everything worked once I updated my network interface's DNS config. :)

2

I've encountered this problem on somebody else's laptop which I was asked to upgrade. After an hour of head scratching, the inspection of /etc/environment revealed that there was anon-proxy installed on the system. Removing it fixed the problem.

So, check your proxy settings in /etc/environment

Marek T
  • 21
  • 1
1

If you have synaptic installed, try to trigger apt-get update within synaptic by clicking on "Reload". Of course, it will also hang but when you abort it, it will print the name of the repository were it stopped, for example:

Failed to fetch http://debian.sur5r.net/i3/dists/quantal/InRelease  
Some index files failed to download. They have been ignored, or old ones used instead.

Temporarily disabling the repositories reported there should fix the problem. In synaptic, you can disable them under "Settings -> Other Software".

1

Found this apt-get update stuck on "Waiting for Headers" when using Windows XP ICS very insightful.

You may want to try installing and running netselect, and copying the generated sources.list to /etc/apt/sources.list

Hope this helps.

Carlos
  • 11
  • 1
0

Just go to System setting->Software & Updates and switch a server works fine for me. I guess my last selected server broke down for unknown reasons.

0

If the issue still persists, I would recommend try a different internet source. Few ISPs block network and network ranges. Has worked for me all the time. Cheers!

0

For me this problem happened inside LXC/LXD container because I had wireguard VPN enabled on host machine.

Workaround: wg-quick down wg0

Solution: iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE

(Surely, wg-quick method and wg0 device name are for my machine, yours may be different)

yaroslaff
  • 11
  • 3
  • I am facing the same issue as you, but setting the iptables rule did not help :-/. Although I used PostUp and PostDown to set and reset the rule, my apt update got stuck almost immediately – Jovan Perovic Nov 20 '22 at 11:52
  • On the second thought, it might not be stuck - just immensely slow... – Jovan Perovic Nov 20 '22 at 11:57
0

Sometimes, all you need to do is just switch to the main server for updates. Updates, depending on your geographical area, sometimes don't come from the main servers for faster deliveries.

For whatever reasons, the relay servers might not be responding as quick as possible to certain requests, so temporarily switching to Main Server for updates should fix it.

When you open your Software and Updates, select "Main Server" from the Download From option.

You should be good to go. Switching to main server always works for me. :)

KhoPhi
  • 1,888