Streamlining apt-get with netselect-apt

High-speed Internet connections have made download times less of a concern than they were in the days of dialup connections. Still, no one wants to wait for downloads longer than necessary, which is where netselect-apt comes in handy.

Netselect-apt is a utility for Debian-based distributions that helps you choose the fastest HTTP mirrors to list in /etc/apt/sources.list. It needs to be run once for each repository you want listed. The command recognizes both the official names (stable, testing, unstable, and experimental) and the code names (jessie, sid), so that netselect-apt unstable and netselect-apt sid give the same results. If no options or repository is named, netselect-apt gives you world-wide results for the stable repository.

The command runs in three stages. It begins by retrieving the set of mirrors from the Debian home site and then creating a temporary file in /tmp.

# netselect-apt --country CA sid
Using distribution sid
Retrieving the list of mirrors from

--2015-06-10 12_50_08--
Resolving (,
Connecting to (||:80... connected.
Length. 363626 (355K) [text/html]
Saving to: '/tmp/netselect-apt.2FfLYw'

In the second stage, netselect-apt applies the options and targets in the command, testing the repository listed using wget, and eliminating duplicate repositories.

Choosing a main Debian mirror using netselect.
(will filter only for mirrors in country CA)
netselect: 11 (11 active) nameserver request(s)...
Duplicate address (,;
    keeping only under first name.
netselect: 5 (5 active) nameserver request(s)...
Duplicate address (,;
    keeping only under first name.
Running netselect to choose 10 out of 11 addresses.

Finally, it lists the ten fastest mirrors (or less, if fewer exist) and writes the fastest to a sources.list file in the present working directory – which means that you should not run it from /etc/apt, where it will overwrite the sources.list that your system is currently using.

Only found 9 hosts out of 10 requested.
The fastest 10 servers seem to be:

Of the hosts tested we choose the fastest valid HTTP:

Writing sources.list.

Name conflicts are automatically resolved, so you can run netselect-apt once for each repository you want in your system’s sources.list, and then copy and paste the results into a single file, and replace your current sources.list. As far as I can tell, netselect-apt gives valid results, but you might want to backup your current sources.list, just in case something goes wrong with the new one.

By default, netselect-apt gives world-wide results, which can take several minutes to produce. You can get quicker results – and, probably faster downloads – if you add the --country CODE option, following the option with a standard country code such as us for the United States or gb for the United Kingdom. You can also use --nonfree to include in the results the section of the repository dedicated to software released under a restricted license, or --ftp to list FTP-based repositories instead of HTTP ones. Similarly, although by default netselect-apt uses the architecture of the machine you are working on, you can also create a sources.list for another architecture with the option --arch.

Should the fastest mirror have any problems, you can copy and paste another of the ten fastest mirrors.

If you truly want the fastest possible downloads, run netselect-apt at several different times of day, to see if your repositories’ speeds differ with the traffic. Such optimization takes a while to setup, but might ensure that you get the best possible download times.

Cover Photo: Need for Speed by craitza for

  • Owain Sutton

    Thanks, I never knew about this – just one thing, it’s GB rather than UK for United Kingdom source, this is one of the cases where ISO 3166-1 and geographic TLDs differ.

    • Paul Brown

      Thanks for spotting that Owain. Corrected.

  • Sergey Maranchuk