17

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

Braiam
  • 69,112

6 Answers6

15

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:

Acquire::ForceIPv4 false;

Save and exit.

Ryan
  • 251
5
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.

swift
  • 3,291
2

The default config uses Ipv6 to establish connections and upgrade the packages and IPv4 is disabled by default. This solution enables precedence for IPv4 addresses by enabling Ipv4. It did not help to execute it in seconds but did speed up the process a little bit as expected.

This is because parsing either IPv4 or IPV6 should not take way much time even if done with each package. It was IPv6 doing it.

sudo nano /etc/gai.conf

Uncomment the following line:

precedence ::ffff:0:0/96 100

This may be a different line for you. Make sure to select the one with /96 rule as seen above. This is CIDR representation for IPv4 addresses. it enables precedence for the same. By default it is commented out.

Save and exit.

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

This creates a new file and when the config in next line is added it sets the config to false allowing IPV4 traffic.

Add the following line to the new file:

Aquire::ForceIPv4 false;

Save and exit.

1

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.

0

Run

sudo apt-get clean

before running

sudo apt-get update
0

First, 2 facts:
apt-get uses http (port 80) by default in standard linux distros.

apt-get generally downloads ~20MB of data to update the lists. If you just ran apt-get update and run it again it downloads ~100KB of data only.
So if you are able to browse the world wide web (i.e. websites using browser) and you are using standard distros (not customized to use any other port), nothing has been blocked by the admin which is stopping you from running this command.
The problem might be that requests from your machine to current servers being used for updates by apt-get are facing some issues (i.e. it might be just a download issue).
To solve your problem, my suggestions(as you are using ubuntu):

Open update-manager -> click on settings at the bottom left -> click on first tab ubuntu software -> click on the drop down box next to Download from option -> change the server to some place which is nearer to your location by choosing other in the list. Also check the protocol being used for updates. It should be http for general users. -> Now run sudo apt-get update or use update manager to check for updates. Now things should work fine for you. If things don't work even after following this, comment here.


Since it din't help you, it seems to be the problem of obsolete or partial files collected while trying to update some time back.
I would suggest you to run this commands in terminal:

sudo mv /var/cache/apt/archives/partial{,bakjune9}
sudo mv /var/lib/apt/lists{,bakjune9}

These commands will rename the directories where files are stored when apt-get downloads them while updating and upgrading. (You can rename them back if something goes wrong. So no risk of making situation worse than present)
After that run:

sudo apt-get update 

It will download something like 20MB of data.
If it runs successfully, your problem is solved.

Now you should be able to run sudo apt-get upgrade to install the updates.
If it does not, comment here back.

Faizan Akram Dar
  • 4,569
  • 1
  • 25
  • 31
drake01
  • 3,515