How do you select the fastest mirror from the command line?












130















I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?










share|improve this question




















  • 3





    In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

    – Egil
    May 4 '11 at 7:13











  • Related: askubuntu.com/questions/37753/…

    – Jorge Castro
    Apr 6 '12 at 19:13






  • 2





    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 '14 at 11:44











  • Should be slash not hash.

    – Matt H
    May 19 '14 at 22:20
















130















I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?










share|improve this question




















  • 3





    In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

    – Egil
    May 4 '11 at 7:13











  • Related: askubuntu.com/questions/37753/…

    – Jorge Castro
    Apr 6 '12 at 19:13






  • 2





    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 '14 at 11:44











  • Should be slash not hash.

    – Matt H
    May 19 '14 at 22:20














130












130








130


69






I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?










share|improve this question
















I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?







command-line apt repository






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 7 '18 at 10:11









k0pernikus

2,94463063




2,94463063










asked May 4 '11 at 6:35









EvanEvan

1,57052223




1,57052223








  • 3





    In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

    – Egil
    May 4 '11 at 7:13











  • Related: askubuntu.com/questions/37753/…

    – Jorge Castro
    Apr 6 '12 at 19:13






  • 2





    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 '14 at 11:44











  • Should be slash not hash.

    – Matt H
    May 19 '14 at 22:20














  • 3





    In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

    – Egil
    May 4 '11 at 7:13











  • Related: askubuntu.com/questions/37753/…

    – Jorge Castro
    Apr 6 '12 at 19:13






  • 2





    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 '14 at 11:44











  • Should be slash not hash.

    – Matt H
    May 19 '14 at 22:20








3




3





In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

– Egil
May 4 '11 at 7:13





In regular expressions, the . character means any character. If you want it to match a ., you need to escape it with , so us.archive[..] should be us.archive[..]

– Egil
May 4 '11 at 7:13













Related: askubuntu.com/questions/37753/…

– Jorge Castro
Apr 6 '12 at 19:13





Related: askubuntu.com/questions/37753/…

– Jorge Castro
Apr 6 '12 at 19:13




2




2





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





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 '14 at 11:44





@EthanLeroy same here with Ubuntu 12.04.3

– logoff
Jan 10 '14 at 11:44













Should be slash not hash.

– Matt H
May 19 '14 at 22:20





Should be slash not hash.

– Matt H
May 19 '14 at 22:20










13 Answers
13






active

oldest

votes


















21














Pakket netselect-apt

dapper (net): Choose the fastest Debian mirror with netselect
[universe]
0.3.ds1-5: all
hardy (net): Choose the fastest Debian mirror with netselect
[universe]
0.3.ds1-11: all



Pakket apt-spy

dapper (admin): writes a sources.list file based on bandwidth tests
[universe]
3.1-14: amd64 i386 powerpc


Not included in newer Ubuntu due to secturity issues it seems: see: Bug report



But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.






share|improve this answer



















  • 3





    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






  • 7





    This is not the most upvoted, or the best answer any more, check next one

    – ntg
    Jun 10 '15 at 7:54











  • Which answer is the "next one" might have changed.

    – gmatht
    Jan 24 '17 at 4:46











  • apt-spy is gone at debian 9, but netselect-apt is OK

    – netawater
    Nov 21 '17 at 16:05



















140














You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.




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


























  • 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 East
    Jun 29 '13 at 17:03






  • 2





    Related: askubuntu.com/q/319433/11244

    – Till
    Jul 18 '13 at 15:45






  • 23





    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











  • in fact, for example here in Italy this way put in use a mirror that has slow downloading...

    – Pisu
    Jul 15 '15 at 7:11






  • 1





    currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

    – marathon
    Aug 31 '17 at 18:34



















47














Here's one way that will always work, using good old netselect and some grep magic:



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




  • Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)


  • Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)



    sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^"]*"`



  • netselect:





    1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)


    2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)


    3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)




  • This is the backquotes stuff (don't paste, just for explanation)




    wget -q -O- https://launchpad.net/ubuntu/+archivemirrors
    | grep -P -B8 "status(UP|SIX)"
    | grep -o -P "(f|ht)tp://[^"]*"




    1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.

    2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

    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/



    • The "ranks" are an arbitrary metric; lower is usually better.

    • If you're wondering why the kernel.org Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as nz.archive.ubuntu.com!








share|improve this answer





















  • 8





    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











  • @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

    – muru
    Feb 21 '17 at 9:23











  • @muru thanks, I just learned something :)

    – pix
    Feb 22 '17 at 3:17



















21














Oneliner that select best (by download speed) mirror based on mirrors.ubuntu.com for yours ip.



curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' |sort -g -r |head -1| awk '{ print $2  }'





share|improve this answer



















  • 2





    To have more options replace at the end: sort -gr | head -3.

    – Pablo Bianchi
    Mar 4 '17 at 1:55






  • 1





    Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

    – Stéphane Gourichon
    Jun 26 '17 at 13:35











  • yes, so this method is NG.

    – netawater
    Nov 18 '17 at 4:58











  • I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

    – jamesc
    Mar 12 '18 at 12:57











  • This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

    – Phil Miller
    Jun 8 '18 at 21:41



















17














Here is a Python script I wrote that finds mirrors with the lowest TCP latency.



The script also provides bandwidth and status data taken from launchpad, and will generate a new sources.list file automatically or using a mirror chosen from a list.



A usage example that lets you choose from 5 US mirrors with the lowest latency to your machine:



$ apt-select --country US -t 5 --choose





share|improve this answer





















  • 3





    I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

    – Gabriel Mazetto
    Nov 3 '15 at 4:25











  • this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

    – kmonsoor
    Oct 11 '16 at 19:14











  • This is great, since netselect isn't available in newer versions of Ubuntu

    – Tek
    Feb 18 '18 at 7:23











  • Please show how to use it in your post

    – Jonathan
    Oct 31 '18 at 6:21











  • @Jonathan done. Full usage is in the README at the first link.

    – John B
    Nov 1 '18 at 0:07



















5














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
ffum


Please let me know if you find it useful or have any suggestions (=






share|improve this answer


























  • ffum does not work: Connection error.

    – James Fu
    Jul 10 '13 at 8:48













  • It doesn't work: Empty output.

    – Juan Simón
    Aug 27 '13 at 1:06











  • git clone the repo and run node ffum

    – Michael
    Aug 7 '14 at 3:58











  • Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

    – tweak2
    Aug 27 '14 at 16:57



















2














I know this doesn't directly answer the OP's question, but there's a button in the desktop/GUI version of Ubuntu that finds the best mirror for you. It seemed to work pretty well, so I looked into it briefly, but didn't have time to follow up.



The reason I bring it up is because I think it would be pretty straight forward and usable to make it into a command line utility.



If anyone is interested, the test seems to be located in:



/usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


Again, that's about as far as I got, but I figured I'd leave this here in case anyone wanted it. I'll probably pick back up on it when I have a little more time.






share|improve this answer
























  • On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

    – PatKilg
    Jun 9 '18 at 18:07





















0














I use the following to auto select mirrors (and disable deb-src)



sudo sed -i -e 's%http://archive.ubuntu.com/ubuntu%mirror://mirrors.ubuntu.com/mirrors.txt%' -e 's/^deb-src/#deb-src/' /etc/apt/sources.list





share|improve this answer































    0














    If you want a utility to do this you could implement such a utility as a simple bash script like the following. This might be useful if you want to use the utility without needing pip/nodejs.



    #!/bin/bash
    if [ -z "$1" ]
    then
    echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt
    echo OR consider one of...
    for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null`
    do
    (
    host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
    echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' tt'$mirror
    ) &
    done
    wait
    exit 1
    fi

    OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb | head -n1 | cut -d -f2`

    [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig

    cp /etc/apt/sources.list /etc/apt/sources.list.tmp
    sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list





    share|improve this answer

































      0














      The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.



      There are two different working answers to this question below:





      1. Use apt-get's mirror: method


        This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.





      2. Command-line foo using netselect

        Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.


      Use sed to replace mirrors in sources.list



      Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.



      sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list





      share|improve this answer

































        0














        Command That Finds Fast Mirrors



        On Ubuntu 18.04 I got good results by running



         python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


        That prints a list of mirrors organized by "time" (not explained), and then I used one of the mirrors it ranked highest.



        More Details



        For me, it was useful to test a few of the top results output by that command by setting them as my mirror in /etc/apt/sources.list and then doing



        time sudo apt update


        to see how long it took to download the package list from that mirror. I tested the top three suggestions and they were all fast, but one of them was twice as fast as the other two in the time sudo apt update test.



        Here's an example output from python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:



        mirror: es-mirrors.evowise.com - time: 0.183778047562
        mirror: it-mirrors.evowise.com - time: 0.18604683876
        mirror: la-mirrors.evowise.com - time: 0.192630052567
        mirror: ny-mirrors.evowise.com - time: 0.208723068237
        mirror: mirrors.accretive-networks.net - time: 0.385910987854
        mirror: mirror.team-cymru.org - time: 0.46785402298
        mirror: mirrors.psu.ac.th - time: 1.64231991768
        and the winner is: es-mirrors.evowise.com





        share|improve this answer































          -1














          The easiest and efficient way to get the fastest mirror is to use the apt mirror:// source, see



          https://mvogt.wordpress.com/2011/03/21/the-apt-mirror-method/






          share|improve this answer

































            -4














            nice terminal program here:



            # apt-get install netselect-apt

            Available Options

            stable|testing|unstable|experimental|woody|sarge|etch|sid Specify which distribution of Debian to use. By default stable is used.

            -s, --sources
            While generating OUTFILE include also deb-src lines to use with ‘‘apt-get source’’ to obtain Debian source packages.

            -i, --infile INFILE
            Use INFILE instead of mirrors_full for reading mirror list. The file must be in the same format as mirrors_full.

            -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.

            Examples

            If you want non-free repos use the following command

            # netselect-apt -n





            share|improve this answer


























            • that program is for Debian, not Ubuntu.

              – Juan Simón
              Aug 27 '13 at 1:07











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f39922%2fhow-do-you-select-the-fastest-mirror-from-the-command-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            13 Answers
            13






            active

            oldest

            votes








            13 Answers
            13






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            21














            Pakket netselect-apt

            dapper (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-5: all
            hardy (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-11: all



            Pakket apt-spy

            dapper (admin): writes a sources.list file based on bandwidth tests
            [universe]
            3.1-14: amd64 i386 powerpc


            Not included in newer Ubuntu due to secturity issues it seems: see: Bug report



            But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.






            share|improve this answer



















            • 3





              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






            • 7





              This is not the most upvoted, or the best answer any more, check next one

              – ntg
              Jun 10 '15 at 7:54











            • Which answer is the "next one" might have changed.

              – gmatht
              Jan 24 '17 at 4:46











            • apt-spy is gone at debian 9, but netselect-apt is OK

              – netawater
              Nov 21 '17 at 16:05
















            21














            Pakket netselect-apt

            dapper (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-5: all
            hardy (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-11: all



            Pakket apt-spy

            dapper (admin): writes a sources.list file based on bandwidth tests
            [universe]
            3.1-14: amd64 i386 powerpc


            Not included in newer Ubuntu due to secturity issues it seems: see: Bug report



            But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.






            share|improve this answer



















            • 3





              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






            • 7





              This is not the most upvoted, or the best answer any more, check next one

              – ntg
              Jun 10 '15 at 7:54











            • Which answer is the "next one" might have changed.

              – gmatht
              Jan 24 '17 at 4:46











            • apt-spy is gone at debian 9, but netselect-apt is OK

              – netawater
              Nov 21 '17 at 16:05














            21












            21








            21







            Pakket netselect-apt

            dapper (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-5: all
            hardy (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-11: all



            Pakket apt-spy

            dapper (admin): writes a sources.list file based on bandwidth tests
            [universe]
            3.1-14: amd64 i386 powerpc


            Not included in newer Ubuntu due to secturity issues it seems: see: Bug report



            But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.






            share|improve this answer













            Pakket netselect-apt

            dapper (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-5: all
            hardy (net): Choose the fastest Debian mirror with netselect
            [universe]
            0.3.ds1-11: all



            Pakket apt-spy

            dapper (admin): writes a sources.list file based on bandwidth tests
            [universe]
            3.1-14: amd64 i386 powerpc


            Not included in newer Ubuntu due to secturity issues it seems: see: Bug report



            But .. I normally just use ping to find out the speed of a connection to some location. Amount of hops and latency.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 4 '11 at 7:07









            RinzwindRinzwind

            206k28394526




            206k28394526








            • 3





              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






            • 7





              This is not the most upvoted, or the best answer any more, check next one

              – ntg
              Jun 10 '15 at 7:54











            • Which answer is the "next one" might have changed.

              – gmatht
              Jan 24 '17 at 4:46











            • apt-spy is gone at debian 9, but netselect-apt is OK

              – netawater
              Nov 21 '17 at 16:05














            • 3





              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






            • 7





              This is not the most upvoted, or the best answer any more, check next one

              – ntg
              Jun 10 '15 at 7:54











            • Which answer is the "next one" might have changed.

              – gmatht
              Jan 24 '17 at 4:46











            • apt-spy is gone at debian 9, but netselect-apt is OK

              – netawater
              Nov 21 '17 at 16:05








            3




            3





            netselect-apt doesn't seem to be available in Ubuntu 12.04

            – offby1
            Nov 6 '13 at 23:22





            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





            correct: see here bugs.launchpad.net/ubuntu/+source/netselect/+bug/337377

            – Rinzwind
            Nov 7 '13 at 7:41




            7




            7





            This is not the most upvoted, or the best answer any more, check next one

            – ntg
            Jun 10 '15 at 7:54





            This is not the most upvoted, or the best answer any more, check next one

            – ntg
            Jun 10 '15 at 7:54













            Which answer is the "next one" might have changed.

            – gmatht
            Jan 24 '17 at 4:46





            Which answer is the "next one" might have changed.

            – gmatht
            Jan 24 '17 at 4:46













            apt-spy is gone at debian 9, but netselect-apt is OK

            – netawater
            Nov 21 '17 at 16:05





            apt-spy is gone at debian 9, but netselect-apt is OK

            – netawater
            Nov 21 '17 at 16:05













            140














            You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.




            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


























            • 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 East
              Jun 29 '13 at 17:03






            • 2





              Related: askubuntu.com/q/319433/11244

              – Till
              Jul 18 '13 at 15:45






            • 23





              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











            • in fact, for example here in Italy this way put in use a mirror that has slow downloading...

              – Pisu
              Jul 15 '15 at 7:11






            • 1





              currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

              – marathon
              Aug 31 '17 at 18:34
















            140














            You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.




            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


























            • 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 East
              Jun 29 '13 at 17:03






            • 2





              Related: askubuntu.com/q/319433/11244

              – Till
              Jul 18 '13 at 15:45






            • 23





              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











            • in fact, for example here in Italy this way put in use a mirror that has slow downloading...

              – Pisu
              Jul 15 '15 at 7:11






            • 1





              currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

              – marathon
              Aug 31 '17 at 18:34














            140












            140








            140







            You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.




            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















            You don't have to do any searching anymore - as ajmitch has explained, you can use deb mirror to have the best mirror picked for you automatically.




            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














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:25









            Community

            1




            1










            answered Oct 23 '10 at 10:31









            badpbadp

            5,849123652




            5,849123652













            • 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 East
              Jun 29 '13 at 17:03






            • 2





              Related: askubuntu.com/q/319433/11244

              – Till
              Jul 18 '13 at 15:45






            • 23





              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











            • in fact, for example here in Italy this way put in use a mirror that has slow downloading...

              – Pisu
              Jul 15 '15 at 7:11






            • 1





              currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

              – marathon
              Aug 31 '17 at 18:34



















            • 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 East
              Jun 29 '13 at 17:03






            • 2





              Related: askubuntu.com/q/319433/11244

              – Till
              Jul 18 '13 at 15:45






            • 23





              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











            • in fact, for example here in Italy this way put in use a mirror that has slow downloading...

              – Pisu
              Jul 15 '15 at 7:11






            • 1





              currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

              – marathon
              Aug 31 '17 at 18:34

















            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 East
            Jun 29 '13 at 17:03





            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 East
            Jun 29 '13 at 17:03




            2




            2





            Related: askubuntu.com/q/319433/11244

            – Till
            Jul 18 '13 at 15:45





            Related: askubuntu.com/q/319433/11244

            – Till
            Jul 18 '13 at 15:45




            23




            23





            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





            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













            in fact, for example here in Italy this way put in use a mirror that has slow downloading...

            – Pisu
            Jul 15 '15 at 7:11





            in fact, for example here in Italy this way put in use a mirror that has slow downloading...

            – Pisu
            Jul 15 '15 at 7:11




            1




            1





            currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

            – marathon
            Aug 31 '17 at 18:34





            currently broken: bugs.launchpad.net/ubuntu/+source/apt/+bug/1613184

            – marathon
            Aug 31 '17 at 18:34











            47














            Here's one way that will always work, using good old netselect and some grep magic:



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




            • Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)


            • Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)



              sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^"]*"`



            • netselect:





              1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)


              2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)


              3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)




            • This is the backquotes stuff (don't paste, just for explanation)




              wget -q -O- https://launchpad.net/ubuntu/+archivemirrors
              | grep -P -B8 "status(UP|SIX)"
              | grep -o -P "(f|ht)tp://[^"]*"




              1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.

              2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

              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/



              • The "ranks" are an arbitrary metric; lower is usually better.

              • If you're wondering why the kernel.org Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as nz.archive.ubuntu.com!








            share|improve this answer





















            • 8





              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











            • @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

              – muru
              Feb 21 '17 at 9:23











            • @muru thanks, I just learned something :)

              – pix
              Feb 22 '17 at 3:17
















            47














            Here's one way that will always work, using good old netselect and some grep magic:



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




            • Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)


            • Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)



              sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^"]*"`



            • netselect:





              1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)


              2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)


              3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)




            • This is the backquotes stuff (don't paste, just for explanation)




              wget -q -O- https://launchpad.net/ubuntu/+archivemirrors
              | grep -P -B8 "status(UP|SIX)"
              | grep -o -P "(f|ht)tp://[^"]*"




              1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.

              2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

              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/



              • The "ranks" are an arbitrary metric; lower is usually better.

              • If you're wondering why the kernel.org Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as nz.archive.ubuntu.com!








            share|improve this answer





















            • 8





              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











            • @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

              – muru
              Feb 21 '17 at 9:23











            • @muru thanks, I just learned something :)

              – pix
              Feb 22 '17 at 3:17














            47












            47








            47







            Here's one way that will always work, using good old netselect and some grep magic:



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




            • Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)


            • Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)



              sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^"]*"`



            • netselect:





              1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)


              2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)


              3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)




            • This is the backquotes stuff (don't paste, just for explanation)




              wget -q -O- https://launchpad.net/ubuntu/+archivemirrors
              | grep -P -B8 "status(UP|SIX)"
              | grep -o -P "(f|ht)tp://[^"]*"




              1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.

              2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

              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/



              • The "ranks" are an arbitrary metric; lower is usually better.

              • If you're wondering why the kernel.org Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as nz.archive.ubuntu.com!








            share|improve this answer















            Here's one way that will always work, using good old netselect and some grep magic:



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




            • Download and dpkg -i netselect for your architecture from the Debian website. (it's about 125 KB, no dependencies)


            • Find the fastest Ubuntu mirrors from your location, either up-to-date or at most six hours behind with this (I'll explain it below, sorry it doesn't split up nicely in Markdown)



              sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^"]*"`



            • netselect:





              1. -v makes it a little verbose -- you want to see progress dots and messages telling you different mirrors mapping to the same IP were merged :)


              2. -sN controls how many mirrors you want at the end (e.g. top 10 mirrors)


              3. -tN is how long each mirror is speed-tested (default is 10; the higher the number, the longer it takes but the more reliable the results.)




            • This is the backquotes stuff (don't paste, just for explanation)




              wget -q -O- https://launchpad.net/ubuntu/+archivemirrors
              | grep -P -B8 "status(UP|SIX)"
              | grep -o -P "(f|ht)tp://[^"]*"




              1. wget pulls the latest mirror status from https://launchpad.net/ubuntu/+archivemirrors.

              2. The first grep extracts mirrors that are up-to-date or six-hours behind, along with 8 lines of previous context which includes the actual ftp/http URLs

              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/



              • The "ranks" are an arbitrary metric; lower is usually better.

              • If you're wondering why the kernel.org Sweden-EU mirror and an NZ mirror are in the top three from California, well, so am I ;-) The truth is that netselect doesn't always choose the most appropriate URL to display when multiple mirrors map to a single IP; number 3 is also known as nz.archive.ubuntu.com!









            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 21 '17 at 9:16









            pix

            368210




            368210










            answered May 24 '12 at 6:45









            ishish

            115k29265293




            115k29265293








            • 8





              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











            • @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

              – muru
              Feb 21 '17 at 9:23











            • @muru thanks, I just learned something :)

              – pix
              Feb 22 '17 at 3:17














            • 8





              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











            • @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

              – muru
              Feb 21 '17 at 9:23











            • @muru thanks, I just learned something :)

              – pix
              Feb 22 '17 at 3:17








            8




            8





            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





            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













            @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

            – muru
            Feb 21 '17 at 9:23





            @pix I approved your edit, but it's not command substitution that results in newlines being replaced. It's the subsequent field splitting that removed the newlines. Command substitution only removes trailing newlines.

            – muru
            Feb 21 '17 at 9:23













            @muru thanks, I just learned something :)

            – pix
            Feb 22 '17 at 3:17





            @muru thanks, I just learned something :)

            – pix
            Feb 22 '17 at 3:17











            21














            Oneliner that select best (by download speed) mirror based on mirrors.ubuntu.com for yours ip.



            curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' |sort -g -r |head -1| awk '{ print $2  }'





            share|improve this answer



















            • 2





              To have more options replace at the end: sort -gr | head -3.

              – Pablo Bianchi
              Mar 4 '17 at 1:55






            • 1





              Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

              – Stéphane Gourichon
              Jun 26 '17 at 13:35











            • yes, so this method is NG.

              – netawater
              Nov 18 '17 at 4:58











            • I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

              – jamesc
              Mar 12 '18 at 12:57











            • This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

              – Phil Miller
              Jun 8 '18 at 21:41
















            21














            Oneliner that select best (by download speed) mirror based on mirrors.ubuntu.com for yours ip.



            curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' |sort -g -r |head -1| awk '{ print $2  }'





            share|improve this answer



















            • 2





              To have more options replace at the end: sort -gr | head -3.

              – Pablo Bianchi
              Mar 4 '17 at 1:55






            • 1





              Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

              – Stéphane Gourichon
              Jun 26 '17 at 13:35











            • yes, so this method is NG.

              – netawater
              Nov 18 '17 at 4:58











            • I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

              – jamesc
              Mar 12 '18 at 12:57











            • This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

              – Phil Miller
              Jun 8 '18 at 21:41














            21












            21








            21







            Oneliner that select best (by download speed) mirror based on mirrors.ubuntu.com for yours ip.



            curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' |sort -g -r |head -1| awk '{ print $2  }'





            share|improve this answer













            Oneliner that select best (by download speed) mirror based on mirrors.ubuntu.com for yours ip.



            curl -s http://mirrors.ubuntu.com/mirrors.txt | xargs -n1 -I {} sh -c 'echo `curl -r 0-102400 -s -w %{speed_download} -o /dev/null {}/ls-lR.gz` {}' |sort -g -r |head -1| awk '{ print $2  }'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 10 '16 at 19:40









            KAndyKAndy

            31123




            31123








            • 2





              To have more options replace at the end: sort -gr | head -3.

              – Pablo Bianchi
              Mar 4 '17 at 1:55






            • 1





              Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

              – Stéphane Gourichon
              Jun 26 '17 at 13:35











            • yes, so this method is NG.

              – netawater
              Nov 18 '17 at 4:58











            • I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

              – jamesc
              Mar 12 '18 at 12:57











            • This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

              – Phil Miller
              Jun 8 '18 at 21:41














            • 2





              To have more options replace at the end: sort -gr | head -3.

              – Pablo Bianchi
              Mar 4 '17 at 1:55






            • 1





              Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

              – Stéphane Gourichon
              Jun 26 '17 at 13:35











            • yes, so this method is NG.

              – netawater
              Nov 18 '17 at 4:58











            • I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

              – jamesc
              Mar 12 '18 at 12:57











            • This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

              – Phil Miller
              Jun 8 '18 at 21:41








            2




            2





            To have more options replace at the end: sort -gr | head -3.

            – Pablo Bianchi
            Mar 4 '17 at 1:55





            To have more options replace at the end: sort -gr | head -3.

            – Pablo Bianchi
            Mar 4 '17 at 1:55




            1




            1





            Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

            – Stéphane Gourichon
            Jun 26 '17 at 13:35





            Currently, curl -s http://mirrors.ubuntu.com/mirrors.txt returns only one line: http://archive.ubuntu.com/ubuntu/ which defeats the purpose of choosing among several. :-/

            – Stéphane Gourichon
            Jun 26 '17 at 13:35













            yes, so this method is NG.

            – netawater
            Nov 18 '17 at 4:58





            yes, so this method is NG.

            – netawater
            Nov 18 '17 at 4:58













            I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

            – jamesc
            Mar 12 '18 at 12:57





            I found the curl part of this answer helpful because curl -r 0-102400 -o /dev/null [server_url]/ls-lR.gz where [server_url] is the base mirror URL listed in mirrors.txt, allows a speed comparison of the first ~100K of the index file from the mirror.

            – jamesc
            Mar 12 '18 at 12:57













            This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

            – Phil Miller
            Jun 8 '18 at 21:41





            This tests transfer speed, which is definitely an improvement over netselect. It's only downloading 10k from each server, which may not be a great representation of steady transfer speed on faster connections, though. Increase that 102400 to test with a larger download

            – Phil Miller
            Jun 8 '18 at 21:41











            17














            Here is a Python script I wrote that finds mirrors with the lowest TCP latency.



            The script also provides bandwidth and status data taken from launchpad, and will generate a new sources.list file automatically or using a mirror chosen from a list.



            A usage example that lets you choose from 5 US mirrors with the lowest latency to your machine:



            $ apt-select --country US -t 5 --choose





            share|improve this answer





















            • 3





              I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

              – Gabriel Mazetto
              Nov 3 '15 at 4:25











            • this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

              – kmonsoor
              Oct 11 '16 at 19:14











            • This is great, since netselect isn't available in newer versions of Ubuntu

              – Tek
              Feb 18 '18 at 7:23











            • Please show how to use it in your post

              – Jonathan
              Oct 31 '18 at 6:21











            • @Jonathan done. Full usage is in the README at the first link.

              – John B
              Nov 1 '18 at 0:07
















            17














            Here is a Python script I wrote that finds mirrors with the lowest TCP latency.



            The script also provides bandwidth and status data taken from launchpad, and will generate a new sources.list file automatically or using a mirror chosen from a list.



            A usage example that lets you choose from 5 US mirrors with the lowest latency to your machine:



            $ apt-select --country US -t 5 --choose





            share|improve this answer





















            • 3





              I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

              – Gabriel Mazetto
              Nov 3 '15 at 4:25











            • this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

              – kmonsoor
              Oct 11 '16 at 19:14











            • This is great, since netselect isn't available in newer versions of Ubuntu

              – Tek
              Feb 18 '18 at 7:23











            • Please show how to use it in your post

              – Jonathan
              Oct 31 '18 at 6:21











            • @Jonathan done. Full usage is in the README at the first link.

              – John B
              Nov 1 '18 at 0:07














            17












            17








            17







            Here is a Python script I wrote that finds mirrors with the lowest TCP latency.



            The script also provides bandwidth and status data taken from launchpad, and will generate a new sources.list file automatically or using a mirror chosen from a list.



            A usage example that lets you choose from 5 US mirrors with the lowest latency to your machine:



            $ apt-select --country US -t 5 --choose





            share|improve this answer















            Here is a Python script I wrote that finds mirrors with the lowest TCP latency.



            The script also provides bandwidth and status data taken from launchpad, and will generate a new sources.list file automatically or using a mirror chosen from a list.



            A usage example that lets you choose from 5 US mirrors with the lowest latency to your machine:



            $ apt-select --country US -t 5 --choose






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 '18 at 13:41









            N0rbert

            23k649109




            23k649109










            answered Jun 10 '14 at 23:58









            John BJohn B

            43168




            43168








            • 3





              I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

              – Gabriel Mazetto
              Nov 3 '15 at 4:25











            • this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

              – kmonsoor
              Oct 11 '16 at 19:14











            • This is great, since netselect isn't available in newer versions of Ubuntu

              – Tek
              Feb 18 '18 at 7:23











            • Please show how to use it in your post

              – Jonathan
              Oct 31 '18 at 6:21











            • @Jonathan done. Full usage is in the README at the first link.

              – John B
              Nov 1 '18 at 0:07














            • 3





              I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

              – Gabriel Mazetto
              Nov 3 '15 at 4:25











            • this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

              – kmonsoor
              Oct 11 '16 at 19:14











            • This is great, since netselect isn't available in newer versions of Ubuntu

              – Tek
              Feb 18 '18 at 7:23











            • Please show how to use it in your post

              – Jonathan
              Oct 31 '18 at 6:21











            • @Jonathan done. Full usage is in the README at the first link.

              – John B
              Nov 1 '18 at 0:07








            3




            3





            I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

            – Gabriel Mazetto
            Nov 3 '15 at 4:25





            I want to let you know that I've made a debian package with your script that is ready to be used in a very easy and straightforward way: github.com/brodock/apt-select/releases/tag/0.1.0

            – Gabriel Mazetto
            Nov 3 '15 at 4:25













            this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

            – kmonsoor
            Oct 11 '16 at 19:14





            this is a perfect solution, as I've tried the other methods. to make noob friendly, I've written a post detailing this method:. blog.kmonsoor.com/…

            – kmonsoor
            Oct 11 '16 at 19:14













            This is great, since netselect isn't available in newer versions of Ubuntu

            – Tek
            Feb 18 '18 at 7:23





            This is great, since netselect isn't available in newer versions of Ubuntu

            – Tek
            Feb 18 '18 at 7:23













            Please show how to use it in your post

            – Jonathan
            Oct 31 '18 at 6:21





            Please show how to use it in your post

            – Jonathan
            Oct 31 '18 at 6:21













            @Jonathan done. Full usage is in the README at the first link.

            – John B
            Nov 1 '18 at 0:07





            @Jonathan done. Full usage is in the README at the first link.

            – John B
            Nov 1 '18 at 0:07











            5














            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
            ffum


            Please let me know if you find it useful or have any suggestions (=






            share|improve this answer


























            • ffum does not work: Connection error.

              – James Fu
              Jul 10 '13 at 8:48













            • It doesn't work: Empty output.

              – Juan Simón
              Aug 27 '13 at 1:06











            • git clone the repo and run node ffum

              – Michael
              Aug 7 '14 at 3:58











            • Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

              – tweak2
              Aug 27 '14 at 16:57
















            5














            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
            ffum


            Please let me know if you find it useful or have any suggestions (=






            share|improve this answer


























            • ffum does not work: Connection error.

              – James Fu
              Jul 10 '13 at 8:48













            • It doesn't work: Empty output.

              – Juan Simón
              Aug 27 '13 at 1:06











            • git clone the repo and run node ffum

              – Michael
              Aug 7 '14 at 3:58











            • Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

              – tweak2
              Aug 27 '14 at 16:57














            5












            5








            5







            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
            ffum


            Please let me know if you find it useful or have any suggestions (=






            share|improve this answer















            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
            ffum


            Please let me know if you find it useful or have any suggestions (=







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 14 '13 at 17:00









            Jorge Castro

            36.4k105422617




            36.4k105422617










            answered May 14 '13 at 16:56









            tentaculotentaculo

            5911




            5911













            • ffum does not work: Connection error.

              – James Fu
              Jul 10 '13 at 8:48













            • It doesn't work: Empty output.

              – Juan Simón
              Aug 27 '13 at 1:06











            • git clone the repo and run node ffum

              – Michael
              Aug 7 '14 at 3:58











            • Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

              – tweak2
              Aug 27 '14 at 16:57



















            • ffum does not work: Connection error.

              – James Fu
              Jul 10 '13 at 8:48













            • It doesn't work: Empty output.

              – Juan Simón
              Aug 27 '13 at 1:06











            • git clone the repo and run node ffum

              – Michael
              Aug 7 '14 at 3:58











            • Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

              – tweak2
              Aug 27 '14 at 16:57

















            ffum does not work: Connection error.

            – James Fu
            Jul 10 '13 at 8:48







            ffum does not work: Connection error.

            – James Fu
            Jul 10 '13 at 8:48















            It doesn't work: Empty output.

            – Juan Simón
            Aug 27 '13 at 1:06





            It doesn't work: Empty output.

            – Juan Simón
            Aug 27 '13 at 1:06













            git clone the repo and run node ffum

            – Michael
            Aug 7 '14 at 3:58





            git clone the repo and run node ffum

            – Michael
            Aug 7 '14 at 3:58













            Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

            – tweak2
            Aug 27 '14 at 16:57





            Awesome, works for me! I had a bug where it was looking for node instead of nodejs... also would be cool to have some verbose of each tested archive speed.

            – tweak2
            Aug 27 '14 at 16:57











            2














            I know this doesn't directly answer the OP's question, but there's a button in the desktop/GUI version of Ubuntu that finds the best mirror for you. It seemed to work pretty well, so I looked into it briefly, but didn't have time to follow up.



            The reason I bring it up is because I think it would be pretty straight forward and usable to make it into a command line utility.



            If anyone is interested, the test seems to be located in:



            /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


            Again, that's about as far as I got, but I figured I'd leave this here in case anyone wanted it. I'll probably pick back up on it when I have a little more time.






            share|improve this answer
























            • On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

              – PatKilg
              Jun 9 '18 at 18:07


















            2














            I know this doesn't directly answer the OP's question, but there's a button in the desktop/GUI version of Ubuntu that finds the best mirror for you. It seemed to work pretty well, so I looked into it briefly, but didn't have time to follow up.



            The reason I bring it up is because I think it would be pretty straight forward and usable to make it into a command line utility.



            If anyone is interested, the test seems to be located in:



            /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


            Again, that's about as far as I got, but I figured I'd leave this here in case anyone wanted it. I'll probably pick back up on it when I have a little more time.






            share|improve this answer
























            • On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

              – PatKilg
              Jun 9 '18 at 18:07
















            2












            2








            2







            I know this doesn't directly answer the OP's question, but there's a button in the desktop/GUI version of Ubuntu that finds the best mirror for you. It seemed to work pretty well, so I looked into it briefly, but didn't have time to follow up.



            The reason I bring it up is because I think it would be pretty straight forward and usable to make it into a command line utility.



            If anyone is interested, the test seems to be located in:



            /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


            Again, that's about as far as I got, but I figured I'd leave this here in case anyone wanted it. I'll probably pick back up on it when I have a little more time.






            share|improve this answer













            I know this doesn't directly answer the OP's question, but there's a button in the desktop/GUI version of Ubuntu that finds the best mirror for you. It seemed to work pretty well, so I looked into it briefly, but didn't have time to follow up.



            The reason I bring it up is because I think it would be pretty straight forward and usable to make it into a command line utility.



            If anyone is interested, the test seems to be located in:



            /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


            Again, that's about as far as I got, but I figured I'd leave this here in case anyone wanted it. I'll probably pick back up on it when I have a little more time.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 29 '16 at 21:35









            copeland3300copeland3300

            1212




            1212













            • On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

              – PatKilg
              Jun 9 '18 at 18:07





















            • On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

              – PatKilg
              Jun 9 '18 at 18:07



















            On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

            – PatKilg
            Jun 9 '18 at 18:07







            On 18.04, this script detects when it is invoked as an application (as main) from a terminal....and just prints its results to the terminal. Make sure to give it enough time to complete. $ python3 /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py >> [top 5 omitted] and the winner is: ny-mirrors.evowise.com

            – PatKilg
            Jun 9 '18 at 18:07













            0














            I use the following to auto select mirrors (and disable deb-src)



            sudo sed -i -e 's%http://archive.ubuntu.com/ubuntu%mirror://mirrors.ubuntu.com/mirrors.txt%' -e 's/^deb-src/#deb-src/' /etc/apt/sources.list





            share|improve this answer




























              0














              I use the following to auto select mirrors (and disable deb-src)



              sudo sed -i -e 's%http://archive.ubuntu.com/ubuntu%mirror://mirrors.ubuntu.com/mirrors.txt%' -e 's/^deb-src/#deb-src/' /etc/apt/sources.list





              share|improve this answer


























                0












                0








                0







                I use the following to auto select mirrors (and disable deb-src)



                sudo sed -i -e 's%http://archive.ubuntu.com/ubuntu%mirror://mirrors.ubuntu.com/mirrors.txt%' -e 's/^deb-src/#deb-src/' /etc/apt/sources.list





                share|improve this answer













                I use the following to auto select mirrors (and disable deb-src)



                sudo sed -i -e 's%http://archive.ubuntu.com/ubuntu%mirror://mirrors.ubuntu.com/mirrors.txt%' -e 's/^deb-src/#deb-src/' /etc/apt/sources.list






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 9 '16 at 12:37









                iheggieiheggie

                1614




                1614























                    0














                    If you want a utility to do this you could implement such a utility as a simple bash script like the following. This might be useful if you want to use the utility without needing pip/nodejs.



                    #!/bin/bash
                    if [ -z "$1" ]
                    then
                    echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt
                    echo OR consider one of...
                    for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null`
                    do
                    (
                    host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
                    echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' tt'$mirror
                    ) &
                    done
                    wait
                    exit 1
                    fi

                    OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb | head -n1 | cut -d -f2`

                    [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig

                    cp /etc/apt/sources.list /etc/apt/sources.list.tmp
                    sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list





                    share|improve this answer






























                      0














                      If you want a utility to do this you could implement such a utility as a simple bash script like the following. This might be useful if you want to use the utility without needing pip/nodejs.



                      #!/bin/bash
                      if [ -z "$1" ]
                      then
                      echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt
                      echo OR consider one of...
                      for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null`
                      do
                      (
                      host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
                      echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' tt'$mirror
                      ) &
                      done
                      wait
                      exit 1
                      fi

                      OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb | head -n1 | cut -d -f2`

                      [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig

                      cp /etc/apt/sources.list /etc/apt/sources.list.tmp
                      sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list





                      share|improve this answer




























                        0












                        0








                        0







                        If you want a utility to do this you could implement such a utility as a simple bash script like the following. This might be useful if you want to use the utility without needing pip/nodejs.



                        #!/bin/bash
                        if [ -z "$1" ]
                        then
                        echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt
                        echo OR consider one of...
                        for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null`
                        do
                        (
                        host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
                        echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' tt'$mirror
                        ) &
                        done
                        wait
                        exit 1
                        fi

                        OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb | head -n1 | cut -d -f2`

                        [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig

                        cp /etc/apt/sources.list /etc/apt/sources.list.tmp
                        sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list





                        share|improve this answer















                        If you want a utility to do this you could implement such a utility as a simple bash script like the following. This might be useful if you want to use the utility without needing pip/nodejs.



                        #!/bin/bash
                        if [ -z "$1" ]
                        then
                        echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt
                        echo OR consider one of...
                        for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null`
                        do
                        (
                        host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
                        echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' tt'$mirror
                        ) &
                        done
                        wait
                        exit 1
                        fi

                        OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb | head -n1 | cut -d -f2`

                        [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig

                        cp /etc/apt/sources.list /etc/apt/sources.list.tmp
                        sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 29 '17 at 15:26









                        derHugo

                        2,30521531




                        2,30521531










                        answered Jan 24 '17 at 4:52









                        gmathtgmatht

                        40146




                        40146























                            0














                            The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.



                            There are two different working answers to this question below:





                            1. Use apt-get's mirror: method


                              This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.





                            2. Command-line foo using netselect

                              Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.


                            Use sed to replace mirrors in sources.list



                            Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.



                            sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list





                            share|improve this answer






























                              0














                              The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.



                              There are two different working answers to this question below:





                              1. Use apt-get's mirror: method


                                This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.





                              2. Command-line foo using netselect

                                Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.


                              Use sed to replace mirrors in sources.list



                              Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.



                              sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list





                              share|improve this answer




























                                0












                                0








                                0







                                The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.



                                There are two different working answers to this question below:





                                1. Use apt-get's mirror: method


                                  This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.





                                2. Command-line foo using netselect

                                  Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.


                                Use sed to replace mirrors in sources.list



                                Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.



                                sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list





                                share|improve this answer















                                The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as netselect-apt and apt-spy which do not work with Ubuntu.



                                There are two different working answers to this question below:





                                1. Use apt-get's mirror: method


                                  This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.





                                2. Command-line foo using netselect

                                  Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Use sed to replace mirrors in sources.list.


                                Use sed to replace mirrors in sources.list



                                Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.



                                sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                answered May 7 '18 at 10:10


























                                community wiki





                                k0pernikus
























                                    0














                                    Command That Finds Fast Mirrors



                                    On Ubuntu 18.04 I got good results by running



                                     python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


                                    That prints a list of mirrors organized by "time" (not explained), and then I used one of the mirrors it ranked highest.



                                    More Details



                                    For me, it was useful to test a few of the top results output by that command by setting them as my mirror in /etc/apt/sources.list and then doing



                                    time sudo apt update


                                    to see how long it took to download the package list from that mirror. I tested the top three suggestions and they were all fast, but one of them was twice as fast as the other two in the time sudo apt update test.



                                    Here's an example output from python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:



                                    mirror: es-mirrors.evowise.com - time: 0.183778047562
                                    mirror: it-mirrors.evowise.com - time: 0.18604683876
                                    mirror: la-mirrors.evowise.com - time: 0.192630052567
                                    mirror: ny-mirrors.evowise.com - time: 0.208723068237
                                    mirror: mirrors.accretive-networks.net - time: 0.385910987854
                                    mirror: mirror.team-cymru.org - time: 0.46785402298
                                    mirror: mirrors.psu.ac.th - time: 1.64231991768
                                    and the winner is: es-mirrors.evowise.com





                                    share|improve this answer




























                                      0














                                      Command That Finds Fast Mirrors



                                      On Ubuntu 18.04 I got good results by running



                                       python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


                                      That prints a list of mirrors organized by "time" (not explained), and then I used one of the mirrors it ranked highest.



                                      More Details



                                      For me, it was useful to test a few of the top results output by that command by setting them as my mirror in /etc/apt/sources.list and then doing



                                      time sudo apt update


                                      to see how long it took to download the package list from that mirror. I tested the top three suggestions and they were all fast, but one of them was twice as fast as the other two in the time sudo apt update test.



                                      Here's an example output from python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:



                                      mirror: es-mirrors.evowise.com - time: 0.183778047562
                                      mirror: it-mirrors.evowise.com - time: 0.18604683876
                                      mirror: la-mirrors.evowise.com - time: 0.192630052567
                                      mirror: ny-mirrors.evowise.com - time: 0.208723068237
                                      mirror: mirrors.accretive-networks.net - time: 0.385910987854
                                      mirror: mirror.team-cymru.org - time: 0.46785402298
                                      mirror: mirrors.psu.ac.th - time: 1.64231991768
                                      and the winner is: es-mirrors.evowise.com





                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        Command That Finds Fast Mirrors



                                        On Ubuntu 18.04 I got good results by running



                                         python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


                                        That prints a list of mirrors organized by "time" (not explained), and then I used one of the mirrors it ranked highest.



                                        More Details



                                        For me, it was useful to test a few of the top results output by that command by setting them as my mirror in /etc/apt/sources.list and then doing



                                        time sudo apt update


                                        to see how long it took to download the package list from that mirror. I tested the top three suggestions and they were all fast, but one of them was twice as fast as the other two in the time sudo apt update test.



                                        Here's an example output from python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:



                                        mirror: es-mirrors.evowise.com - time: 0.183778047562
                                        mirror: it-mirrors.evowise.com - time: 0.18604683876
                                        mirror: la-mirrors.evowise.com - time: 0.192630052567
                                        mirror: ny-mirrors.evowise.com - time: 0.208723068237
                                        mirror: mirrors.accretive-networks.net - time: 0.385910987854
                                        mirror: mirror.team-cymru.org - time: 0.46785402298
                                        mirror: mirrors.psu.ac.th - time: 1.64231991768
                                        and the winner is: es-mirrors.evowise.com





                                        share|improve this answer













                                        Command That Finds Fast Mirrors



                                        On Ubuntu 18.04 I got good results by running



                                         python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py


                                        That prints a list of mirrors organized by "time" (not explained), and then I used one of the mirrors it ranked highest.



                                        More Details



                                        For me, it was useful to test a few of the top results output by that command by setting them as my mirror in /etc/apt/sources.list and then doing



                                        time sudo apt update


                                        to see how long it took to download the package list from that mirror. I tested the top three suggestions and they were all fast, but one of them was twice as fast as the other two in the time sudo apt update test.



                                        Here's an example output from python /usr/lib/python3/dist-packages/softwareproperties/MirrorTest.py:



                                        mirror: es-mirrors.evowise.com - time: 0.183778047562
                                        mirror: it-mirrors.evowise.com - time: 0.18604683876
                                        mirror: la-mirrors.evowise.com - time: 0.192630052567
                                        mirror: ny-mirrors.evowise.com - time: 0.208723068237
                                        mirror: mirrors.accretive-networks.net - time: 0.385910987854
                                        mirror: mirror.team-cymru.org - time: 0.46785402298
                                        mirror: mirrors.psu.ac.th - time: 1.64231991768
                                        and the winner is: es-mirrors.evowise.com






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jan 19 at 22:34









                                        ntc2ntc2

                                        315211




                                        315211























                                            -1














                                            The easiest and efficient way to get the fastest mirror is to use the apt mirror:// source, see



                                            https://mvogt.wordpress.com/2011/03/21/the-apt-mirror-method/






                                            share|improve this answer






























                                              -1














                                              The easiest and efficient way to get the fastest mirror is to use the apt mirror:// source, see



                                              https://mvogt.wordpress.com/2011/03/21/the-apt-mirror-method/






                                              share|improve this answer




























                                                -1












                                                -1








                                                -1







                                                The easiest and efficient way to get the fastest mirror is to use the apt mirror:// source, see



                                                https://mvogt.wordpress.com/2011/03/21/the-apt-mirror-method/






                                                share|improve this answer















                                                The easiest and efficient way to get the fastest mirror is to use the apt mirror:// source, see



                                                https://mvogt.wordpress.com/2011/03/21/the-apt-mirror-method/







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Apr 10 '16 at 8:32









                                                0xF2

                                                2,33722045




                                                2,33722045










                                                answered Apr 10 '16 at 7:58









                                                daviddavid

                                                1




                                                1























                                                    -4














                                                    nice terminal program here:



                                                    # apt-get install netselect-apt

                                                    Available Options

                                                    stable|testing|unstable|experimental|woody|sarge|etch|sid Specify which distribution of Debian to use. By default stable is used.

                                                    -s, --sources
                                                    While generating OUTFILE include also deb-src lines to use with ‘‘apt-get source’’ to obtain Debian source packages.

                                                    -i, --infile INFILE
                                                    Use INFILE instead of mirrors_full for reading mirror list. The file must be in the same format as mirrors_full.

                                                    -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.

                                                    Examples

                                                    If you want non-free repos use the following command

                                                    # netselect-apt -n





                                                    share|improve this answer


























                                                    • that program is for Debian, not Ubuntu.

                                                      – Juan Simón
                                                      Aug 27 '13 at 1:07
















                                                    -4














                                                    nice terminal program here:



                                                    # apt-get install netselect-apt

                                                    Available Options

                                                    stable|testing|unstable|experimental|woody|sarge|etch|sid Specify which distribution of Debian to use. By default stable is used.

                                                    -s, --sources
                                                    While generating OUTFILE include also deb-src lines to use with ‘‘apt-get source’’ to obtain Debian source packages.

                                                    -i, --infile INFILE
                                                    Use INFILE instead of mirrors_full for reading mirror list. The file must be in the same format as mirrors_full.

                                                    -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.

                                                    Examples

                                                    If you want non-free repos use the following command

                                                    # netselect-apt -n





                                                    share|improve this answer


























                                                    • that program is for Debian, not Ubuntu.

                                                      – Juan Simón
                                                      Aug 27 '13 at 1:07














                                                    -4












                                                    -4








                                                    -4







                                                    nice terminal program here:



                                                    # apt-get install netselect-apt

                                                    Available Options

                                                    stable|testing|unstable|experimental|woody|sarge|etch|sid Specify which distribution of Debian to use. By default stable is used.

                                                    -s, --sources
                                                    While generating OUTFILE include also deb-src lines to use with ‘‘apt-get source’’ to obtain Debian source packages.

                                                    -i, --infile INFILE
                                                    Use INFILE instead of mirrors_full for reading mirror list. The file must be in the same format as mirrors_full.

                                                    -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.

                                                    Examples

                                                    If you want non-free repos use the following command

                                                    # netselect-apt -n





                                                    share|improve this answer















                                                    nice terminal program here:



                                                    # apt-get install netselect-apt

                                                    Available Options

                                                    stable|testing|unstable|experimental|woody|sarge|etch|sid Specify which distribution of Debian to use. By default stable is used.

                                                    -s, --sources
                                                    While generating OUTFILE include also deb-src lines to use with ‘‘apt-get source’’ to obtain Debian source packages.

                                                    -i, --infile INFILE
                                                    Use INFILE instead of mirrors_full for reading mirror list. The file must be in the same format as mirrors_full.

                                                    -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.

                                                    Examples

                                                    If you want non-free repos use the following command

                                                    # netselect-apt -n






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jan 4 '12 at 9:51









                                                    Scott Severance

                                                    10.4k73568




                                                    10.4k73568










                                                    answered Jan 4 '12 at 8:35









                                                    debsiddebsid

                                                    9




                                                    9













                                                    • that program is for Debian, not Ubuntu.

                                                      – Juan Simón
                                                      Aug 27 '13 at 1:07



















                                                    • that program is for Debian, not Ubuntu.

                                                      – Juan Simón
                                                      Aug 27 '13 at 1:07

















                                                    that program is for Debian, not Ubuntu.

                                                    – Juan Simón
                                                    Aug 27 '13 at 1:07





                                                    that program is for Debian, not Ubuntu.

                                                    – Juan Simón
                                                    Aug 27 '13 at 1:07


















                                                    draft saved

                                                    draft discarded




















































                                                    Thanks for contributing an answer to Ask Ubuntu!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f39922%2fhow-do-you-select-the-fastest-mirror-from-the-command-line%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                                    Mangá

                                                    Eduardo VII do Reino Unido