Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Downloading from the main Ubuntu archive is slow even when it's not release day, how can I get apt-get to automatically use a mirror that is close to me?

share|improve this question
    
Related: askubuntu.com/questions/39922/… –  Jorge Castro Apr 6 '12 at 19:13
add comment

7 Answers

up vote 92 down vote accepted

apt-get now supports a 'mirror' method that will automatically select a good mirror based on your location. Putting:

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
deb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse

on the top in your /etc/apt/sources.list file should be all that is needed to make it automatically pick a mirror for you based on your geographical location.

Lucid (10.04), Maverick (10.10), Natty (11.04), And Oneiric (11.10) users can replace precise with the appropriate name.

share|improve this answer
4  
Just to clarify, is this instead of the usual lines or aswell as? –  Hamish Downer Mar 22 '12 at 7:25
2  
That works when you're lucky. I've disabled it on our desktops now because it would often return broken mirrors (the kind that give you 403 occasionally). –  ℝaphink Apr 27 '12 at 21:22
1  
@HamishDowner This is beside the lines. At the top of the file. –  hexafraction Jul 6 '12 at 23:25
1  
Great tip. Just note that after making the change you need to run sudo apt-get update before doing any apt-get install for it to use your closest mirror. –  Simon Jun 29 '13 at 17:04
    
@ the first apt-get update it didn't work but at the second apt-get update it did. –  mojo706 Jul 30 '13 at 5:16
add comment

I've always gone with the 'select best server' GUI tool: from Ubuntu Software Center, go to Edit -> Software Sources in the menu. (You can also do this from the Preferences for Synaptic or the Update Manager.)

Under the Ubuntu Software tab there's a drop-down next to "Download from:" If you select "Other..." you'll get a button that says "Select Best Server"; clicking on it gets Ubuntu to run some tests to see what mirror will give the best download speed.

I can't comment on whether this is better or worse than the method you found for yourself. Perhaps someone with some expertise on the issue can comment!


Here are some screenshots for the graphical method, as Jorge suggested:

  1. Open the Ubuntu Software Center, click on Edit in the global menu, and go to 'Software Sources...'

  2. Click on the drop-down menu next to 'Download From' and select 'Other...'

  3. Click on Select Best Server

  4. The best server is highlighted. Click Choose Server and you're done!

enter image description here

share|improve this answer
2  
Is there a command line way to do the same?. I get different best servers each day. It will be useful to select the best before using apt-get –  balki Oct 28 '12 at 16:13
    
Maybe the one mentioned in the post above mine? I usually just "set it and forget it" - updates usually come pretty quickly anyway. –  Sean Fitzpatrick Dec 3 '12 at 2:59
add comment

For a fast upgrade, I've downloaded the alternate CD using torrents. After the upgrade in this way, I still ended up with a system which has still not all updates (probably after the ISO was packed).

After a quick search, I ended up on the list of mirrors on Launchpad. Search for your country and test some. I live in the Netherlands and got only 75kB/s speed, much lower than my usual speed. The ubuntu.mirror.cambrium.nl mirror did not work for me, but ubuntu.mirror.astratoip.net did. Replace the mirror accordingly and run the below commands:

sudo sed 's@archive.ubuntu.com@ubuntu.mirror.atratoip.net@' -i /etc/apt/sources.list
sudo apt-get update

Replace archive.ubuntu.com by your current mirror.

share|improve this answer
add comment

The Geographic location does not always give the best mirror. For example, I live in BC Canada, and most who are in this province should find a mirror in BC, California, or any Pacific state, maybe even Arizona.

However, here in the north my ISP (unlike the phone company) has only one fiber line out of this city, and it goes straight to Calgary (1000km east of here) where it plugs a NEX shared with the line to ucalgary, where they have a lovely debian and ubuntu and who-knows-what-else mirror. It seems the university has the same ISP as I, and so transfer rates are measured in megabytes per second, as opposed to the 50-100 kilobytes per second I get from a default mirror.

So. I recommend knowing your local internet network topology. Pretty things such as Network Exchanges can make for a fast connection to specific places. Staying on your ISP's network can bypass some speed throttles you might otherwise have to the outside world.

Thanks to the post regarding the GUI tool to change this, I found that mirror and set it as default. Good show for this topic!

share|improve this answer
    
Is it ubuntu-archives.mirror.nexicom.net you are referring to? –  lrkwz Jan 29 '13 at 10:58
add comment

You can also use mirrors hosted on Amazon's S3 service, which has a bunch of capacity and should be fast for users where an Amazon region is close:

You can use whichever region is closest to you, you can either manually add these to /etc/apt/sources.list/ or paste them into the custom URL field of the software sources application. I am including the updates and security sections too for completeness.

  • East Coast US (this is the default mirror for the US east mirrors):

    deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • West Coast US (California):

    deb http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • West Coast US (Oregon)

    deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • South America (São Paulo, Brazil)

    deb http://sa-east-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://sa-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://sa-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • Western Europe (Dublin, Ireland)

    deb http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • SouthEast Asia (Singapore)

    deb http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    
  • NorthEast Asia (Tokyo)

    deb http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
    deb http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
    deb http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
    

Note: Unlike most other Ubuntu mirrors, the Amazon S3 mirrors do not provide HTTP directory listings; e.g. if you try to access http://us-east-1.ec2.archive.ubuntu.com/ubuntu/, you will get an "access denied" page. This is normal, and apt-get will not be affected.

Please NOTE: Due to a bug with S3 in every region except east-1, users may have problems with download packages. Amazon has fixed this in east-1 and fixes for the other regions are pending.

In the meantime, the maintainers strongly suggests that you put the following in /etc/apt/apt.conf.d/90-apt-no-pipeling.conf if you are outside of east-1:

    Acquire::http::Pipeline-Depth "0";

Alternatively, you may use the following command:

    sudo apt-get -o Acquire::http::Pipeline-Depth=0 ....

If you get odd message failure messages try either of these options.

share|improve this answer
add comment

A tip for users of Kubuntu 12.04...

From Muon Software Centre:

  • Settings > Configure Software Sources

Then on the Kubuntu Software tab:

  • Select "Other" from the "Download from:" drop-down list
  • Click "Select Best Server" button - this will ping all servers in the list

This will select the server with the quickest ping (fastest server at the time)

I'm in the UK, but my fastest server is "server for Nepal". - about 10 times faster than what I was getting with the default server for UK!

share|improve this answer
add comment

I'm using Ubuntu Server 12.0.4 (precise pangolin).

My problem was that apt-get was hanging anytime it tried to retrieve something from us.archive.ubuntu.com

I added the below lines to the top of my /etc/apt/sources.list file (taken from @ajmitch answer above) and commented out everything else. This solved my problem and now install and update are working as expected.

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
deb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse
share|improve this answer
    
Tried this, it is slooowww. (been running for 45 minutes now and still isn't done). –  spuder Feb 24 at 5:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.