Take the 2-minute tour ×


There are two different working answers to this question below:

  1. Use apt-get's mirror: method
  2. Command-line foo using netselect


Use sed to replace mirrors in sources.list

sudo sed -i -e 's#us.archive.ubuntu.com/mirror.math.ucdavis.edu#g' /etc/apt/sources.list
share|improve this question
Related: askubuntu.com/questions/37753/… –  Jorge Castro Apr 6 '12 at 19:13
In my case I had to replace the # signs with slashes (/). Otherwise I got sed: -e expression #1, char 53: unterminated s' command`. –  Ethan Leroy Oct 18 '13 at 21:18
@EthanLeroy same here with Ubuntu 12.04.3 –  logoff Jan 10 at 11:44
add comment

5 Answers

up vote 7 down vote accepted
Pakket netselect-apt

    dapper (net): Choose the fastest Debian mirror with netselect 
    0.3.ds1-5: all
    hardy (net): Choose the fastest Debian mirror with netselect 
    0.3.ds1-11: all
Pakket apt-spy

    3.1-14: amd64 i386 powerpc



share|improve this answer
netselect-apt doesn't seem to be available in Ubuntu 12.04 –  offby1 Nov 6 '13 at 23:22
correct: see here bugs.launchpad.net/ubuntu/+source/netselect/+bug/337377 –  Rinzwind Nov 7 '13 at 7:41
add comment






share|improve this answer
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:03
Related: askubuntu.com/q/319433/11244 –  Till Jul 18 '13 at 15:45
Nice tip, but unhelpful in my case. It works on geolocation, giving me the local server, which is waaaayy slower where I am. The network temporal distance is the important factor here, not spatial distance. –  jarondl Jul 31 '13 at 8:24
add comment


The terminal-addict's "find best server" hack!


  • netselect:


    | grep -P -B8 "status(UP|SIX)" 
    | | tr '"\n' '  '
    1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.
    3. The second grep extracts these ftp/http URLs
  • Here's a sample output from California, USA:

    60 ftp://mirrors.se.eu.kernel.org/ubuntu/
    70 http://ubuntu.alex-vichev.info/
    77 http://ftp.citylink.co.nz/ubuntu/
    279 http://ubuntu.mirrors.tds.net/pub/ubuntu/
    294 http://mirror.umd.edu/ubuntu/
    332 http://mirrors.rit.edu/ubuntu/
    364 ftp://pf.archive.ubuntu.com/ubuntu/
    378 http://mirror.csclub.uwaterloo.ca/ubuntu/
    399 ftp://ubuntu.mirror.frontiernet.net/ubuntu/
    455 http://ubuntu.mirror.root.lu/ubuntu/
share|improve this answer
netselect picks mirrors that have low udp or icmp latency. It doesn't necessarily pick mirrors that can give more bandwidth. –  Tobu Oct 13 '13 at 19:40
add comment

I developed a simple ping-based nodejs script that tests the servers listed on mirrors.ubuntu.com/mirrors.txt and returns the fastest one:

sudo npm install -g ffum


share|improve this answer
ffum does not work: Connection error. –  James Fu Jul 10 '13 at 8:48
It doesn't work: Empty output. –  Simón Aug 27 '13 at 1:06
add comment

nice terminal program here:

# apt-get install netselect-apt

Available Options


-s, --sources

-i, --infile INFILE

-o, --outfile OUTFILE
Use OUTFILE instead of sources.list.

-n, --nonfree
Include also non-free section while generating OUTFILE.

-f, --ftp
Use FTP mirrors instead of HTTP and generate OUTFILE accordingly.


If you want non-free repos use the following command

# netselect-apt -n
share|improve this answer
that program is for Debian, not Ubuntu. –  Simón Aug 27 '13 at 1:07
add comment

Your Answer


