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?
8 Answers
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.
-
6Just to clarify, is this instead of the usual lines or aswell as? Mar 22, 2012 at 7:25
-
14That 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).– raphinkApr 27, 2012 at 21:22
-
3
-
7Great tip. Just note that after making the change you need to run
sudo apt-get update
before doing anyapt-get install
for it to use your closest mirror. Jun 29, 2013 at 17:04 -
3
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:
Open the Ubuntu Software Center, click on Edit in the global menu, and go to 'Software Sources...'
Click on the drop-down menu next to 'Download From' and select 'Other...'
Click on Select Best Server
The best server is highlighted. Click Choose Server and you're done!
-
12Is 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
– balkiOct 28, 2012 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. Dec 3, 2012 at 2:59
-
1Very good answer because it used sted by step explanation. Big plus it included pictures. Sep 15, 2014 at 10:19
-
1just tried "best server", it directed me to ftp.utexas.edu, which promptly failed to update in the software center. however using the drop-down list was very helpful to find a good mirror. Feb 26, 2015 at 2:05
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!
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.
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!
My Python script apt-smart that finds mirrors automaticly within your country, benchmarks and ranks them by status and speed, finally changes sources.list if you want to.
The differences between apt-smart
and other answer mentioned apt-select
are:
apt-smart
automaticly finds where you are so you don't need to specify the country when you travel abroad.apt-smart
does real HTTP download from each mirror to get more accurate results ( bandwidth & status ) and supports HTTP proxy, whereasapt-select
only usesping
and relies on launchpad 's inaccurate data.apt-smart
is being maintained, whereasapt-select
leaves isusues unfix for almost 3 years.
You can easily install apt-smart
via pip
, for detailed copy'n'paste install commands please see Project Readme.
A usage example that lets you list ranked mirrors within your country:
$ apt-smart -l
With -l
, or --list-mirrors
, you will get ( example output from Travis CI U.S. server ):
---------------------------------------------------------------------------------------------------------
| Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
---------------------------------------------------------------------------------------------------------
| 1 | http://mirrors.gigenet.com/ubuntua... | Yes | No | Up to date | 1.73 MB/s |
| 2 | http://mirror.genesisadaptive.com/... | Yes | No | Up to date | 1.68 MB/s |
| 3 | http://ubuntu.mirrors.tds.net/pub/... | Yes | No | Up to date | 1.4 MB/s |
| 4 | http://repos.forethought.net/ubuntu | Yes | No | Up to date | 1.35 MB/s |
| 5 | http://repo.miserver.it.umich.edu/... | Yes | No | Up to date | 937.62 KB/s |
...
| 75 | http://mirror.cc.vt.edu/pub2/ubuntu | Yes | No | 1 day behind | 659.67 KB/s |
| 76 | http://mirror.atlantic.net/ubuntu | Yes | No | 2 days behind | 351.26 KB/s |
| 77 | http://mirror.lstn.net/ubuntu | Yes | No | 4 days behind | 806.81 KB/s |
| 78 | http://mirrors.usinternet.com/ubun... | Yes | No | 4 weeks behind | 514.31 KB/s |
| 79 | http://mirrors.arpnetworks.com/Ubuntu | Yes | No | 19 weeks behind | 418.94 KB/s |
| 80 | http://mirrors.ocf.berkeley.edu/ub... | Yes | Yes | Up to date | 446.07 KB/s |
---------------------------------------------------------------------------------------------------------
Full URLs which are too long to be shown in above table:
1: http://mirrors.gigenet.com/ubuntuarchive
2: http://mirror.genesisadaptive.com/ubuntu
3: http://ubuntu.mirrors.tds.net/pub/ubuntu
5: http://repo.miserver.it.umich.edu/ubuntu
...
78: http://mirrors.usinternet.com/ubuntu/archive
80: http://mirrors.ocf.berkeley.edu/ubuntu
-
DO NOT copy-paste the same answer to multiple questions. If the questions are similar enough to each other, then you should flag the questions as duplicates of each other and answer only one of them. Otherwise, copy-pasting the same answer everywhere is considered noisy and impolite.– Thomas Ward ♦Sep 30, 2019 at 15:15
-
Simply adding deb mirror lines to /etc/apt/sources.list
will give you duplicate sources. Also, because apt
only checks for duplicate lines, there is no error. We need to replace the original contents of the file to prevent this problem
I made a complete list to replace the original sources list file. This includes the main, restricted, universe, multiverse, proposed, and canonical repositories.
Note: the lines for "proposed" are commented out. Also, the Canonical "partner" repository (closed source and proprietary) doesn't work with mirrors so these lines are unchanged.
First, run the following to make a backup and delete your sources list file:
sudo mv /etc/apt/sources.list /etc/apt/sources.listbackup
Next, use your favorite text editor to copy and paste the following lines into /etc/apt/sources.list
(if you're not on "bionic", I've included a command to fix that in the next step):
## main, restricted, universe, and multiverse repositories
deb mirror://mirrors.ubuntu.com/mirrors.txt bionic main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt bionic-updates main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt bionic-backports main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt bionic-security main restricted universe multiverse
deb-src mirror://mirrors.ubuntu.com/mirrors.txt bionic main restricted universe multiverse
deb-src mirror://mirrors.ubuntu.com/mirrors.txt bionic-updates main restricted universe multiverse
deb-src mirror://mirrors.ubuntu.com/mirrors.txt bionic-backports main restricted universe multiverse
deb-src mirror://mirrors.ubuntu.com/mirrors.txt bionic-security main restricted universe multiverse
## uncomment to enable "proposed" or pre-release software which may be unstable and could cause problems or breaks
#deb mirror://mirrors.ubuntu.com/mirrors.txt bionic-proposed main restricted universe multiverse
#deb-src mirror://mirrors.ubuntu.com/mirrors.txt bionic-proposed main restricted universe multiverse
## Canonical "partner" repository does not work with mirrors
## uncomment to enable the partner repository for proprietary and closed source software
deb http://archive.canonical.com/ubuntu bionic partner
deb-src http://archive.canonical.com/ubuntu bionic partner
After you save the file, run the following command to automatically apply your version of Ubuntu (bionic, eoan, xenial, etc . . .):
sudo sed -i "s/bionic/$(lsb_release -sc)/g" /etc/apt/sources.list
Finally, run the following command to update apt:
sudo apt update
-
I think it should be noted that this appears to choose a good mirror but not necessarily the fastest mirror.– mchidSep 14, 2022 at 21:38
-
-
1@Zeth Yeah, if your repo doesn't have a release file (you get a no release file error), that's a separate issue. AFAIK, my answer shouldn't be related to mariadb mirrors as those are independent of the main ubuntu mirrors. Make sure you still have a mariadb mirror so that you don't miss out on security updates.– mchidOct 12, 2022 at 1:00
Here is a Python script I wrote that returns a list of mirrors with the lowest latency for a specified country.
The script also provides bandwidth and status information taken from the mirrors' launchpad pages and will generate a new sources.list
file using a mirror chosen from the list.