Apt-get take long time to update\upgrade

On my work network any apt-get (or aptitude) commands take a very long time, it's look's like admins blocked some port for it (for unknown reason). For example

sudo apt-get update

take like 2 days and all I get - a very long list of responses like

Get: 36 http://security.ubuntu.com precise-security/universe amd64 Packages [11.6 kB]
Get: 37 http://security.ubuntu.com precise-security/universe amd64 Packages [11.6 kB]
Get: 38 http://security.ubuntu.com precise-security/universe amd64 Packages [11.6 kB]
Get: 39 http://security.ubuntu.com precise-security/universe amd64 Packages [11.6 kB]
Get: 40 http://security.ubuntu.com precise-security/universe amd64 Packages [11.6 kB]

Same situation then I try to download software

Get:1 http://archive.ubuntu.com/ubuntu/ precise/main dash i386 0.5.7-2ubuntu2 [85.8 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ precise/main dash i386 0.5.7-2ubuntu2 [85.8 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ precise/main dash i386 0.5.7-2ubuntu2 [85.8 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ precise/main dash i386 0.5.7-2ubuntu2 [85.8 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ precise/main dash i386 0.5.7-2ubuntu2 [85.8 kB]

Is there something I can do to change port for apt-get or something else


My ubuntu servers were always very fast at apt-get updates and upgrades. Typically the lines on the screen went too fast to be seen. Then all of a sudden they slowed down to a crawl overnight.

It was IPv6 doing it.

I found the following solution:

sudo nano /etc/gai.conf

Uncomment the following line:

precedence ::ffff:0:0/96 100

For me it was line 54 (make sure you don't uncomment the one that ends in 10).

Save and exit.

sudo nano /etc/apt/apt.conf.d/99force-ipv4 # (this is to make a new file)

Add the following line to the new file:

Aquire::ForceIPv4 false;

Save and exit.


sudo nano /etc/gai.conf

add / uncomment these lines:

reload yes
precedence ::ffff:0:0/96 100
precedence ::/0 10

when I updated with above lines my /etc/gai.conf it solved , and it used ipv4 directly instead of ipv6 and installed quickly.


I suggest you begin by measuring your typical Internet/network throughput using one of the performance checking sites. One possibility is www.speedtest.net. You can also use a simple Google search to look for other sites you could use to test your Internet connection speed.

If testing shows that the problem is not a limitation of your Internet connection, then the next step might be to take a look at the answers to this question:
How can I get apt to use a mirror close to me, or choose a faster mirror?

I suggest you start by trying the most popular answer to that question. It boils down to adding the two lines below to the top of /etc/apt/sources.list. This is supposed to encourage the update process to automatically pick a download mirror with better performance.

deb mirror://mirrors.ubuntu.com/mirrors.txt precise main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main restricted universe multiverse
  • Note: The lines above are meant to used with Ubuntu 12.04 (Precise Pangolin). For earlier releases replace precise in the two lines above with the corresponding codename of the release you are using.

    Lucid (10.04), Maverick (10.10), Natty (11.04), Oneiric (11.10)

If this approach does not help or is simply not something you want to do then you might also consider letting Update Manager attempt to pick a "fastest" mirror. This is described in more detail in the other answers to the question I provided a link to above.