Fast Debian downloads
Command Line – Debian Scripts
By combining a few Debian scripts, you can increase your download speed by more than 50 percent. Bruce shows you how.
Over the years, a rich ecosystem of applications has grown around Debian package management. In fact, the available choices are so numerous that some are easy to overlook, especially since some scripts are not in the official repositories of any distribution. Finding compatible scripts can require a lot of searching, often resulting in frustration.
Setting out to maximize download speed, I found several layers of scripts or tools: netselect [1] to find the quickest mirrors for my location, aria2 [2] or Axel [3] to serve as download managers, and apt-fast [4] to make the other scripts' modifications easy to use by placing them in a single command. The procedure can take some time, but, considering that it can increase download speeds by more than 50 percent, the effort seems worthwhile.
Step One: Determine the Fastest Mirrors
In earlier versions of Ubuntu, you could have the fastest mirror selected for you by choosing Settings | Repositories | Download | Other | Best Server. However, this feature has been dropped in the past few years.
Netselect offers a better solution for finding the fastest repositories. Not only does it give you multiple mirrors, which you will want when using download managers, netselect also allows you to consider the factors involved, such as how close a repository is to you, its bandwidth, and its traffic at various times of day. Perhaps no one repository will always be the fastest, but you can check at different times and get an average reading of its speed.
When you research how to find the fastest server, you will find frequent references to netselect-apt. This script is still available and has the advantage of selecting the fastest mirrors for you. However, installing it on a modern Debian-like system results in dependency problems you may not want to deal with. Instead, you should use the newer netselect script. If you are interested in particular mirrors, you can check their address in Debian's list of mirrors [5] or in your distribution's list and enter them in a space-separated list (Figure 1). The output will show the speed of each mirror address in parentheses at the end of its line, and the fastest in the final line, with the lowest score being the fastest. You can also use options to limit the listings and the number of fast mirrors returned. Alternatively, you can get a list of the 10 fastest links (Figure 2) for your circumstances with the code from Listing 1.
Listing 1
Your Top 10 Fastest Links
sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^\"]*"`
Be warned though, that almost 600 mirrors will be checked using the Debian list alone, and the results will take a few minutes to process. Either way, you will want at least five mirrors for the next steps in this procedure. An alternative method for finding the fastest mirrors is apt-smart [6], which can also manage package sources.
Step 2: Set Up a Download Manager
Adding the fastest mirrors to /etc/apt/sources.list
accelerates downloads without any other modification. However, you can increase the download speed even more by adding a download manager such as Axel or aria2. Both are replacements for Wget and available for non-Debian systems, but what is relevant here is that both will attempt to use multiple mirrors to accelerate downloads.
Axel can be configured with options, or, more conveniently, with the fields in /etc/axelrc
(Table 1).
Table 1
Fields in an /etc/axelrc File
Field | Description |
---|---|
reconnect_delay |
Sets the number of seconds Axel waits before trying to reconnect. |
max_speed |
Value is given in bytes per second and dependent on the physical bandwidth. |
num_connections |
Sets the maximum number of connections that Axel will attempt to use. Some servers may not permit multiple connections. |
http_proxy |
Sets a proxy server if no system-wide environmental variable is set. |
no_proxy |
Provides an optional comma-separated list of local domains that Axel should not try to reach through a proxy. |
buffer_size |
Represents the maximum bytes to read from all connections at the same time. |
verbose |
Set to 0 to disable screen messages and 1 to see messages. |
interfaces |
Lists network interfaces with Internet access. If not specified, the first interface found will be used. |
Figure 3 shows a sample minimal axelrc
file. You may want to add additional fields, depending on your hardware. Running Axel verbosely, the output shows the percentage of the download completed and ends with the connections closing and a download summary (Figure 4).
As an alternative to Axel, you may want to use aria2. In aria2, multiple mirrors are added at the command line or, as shown in Figure 5, in a file specified using the option:
--input-file=FILE (-i=FILE)
Naturally, you will want to use the fastest mirrors as determined by netselect (see above). However, unlike Axel, aria2 does not show how each mirror was used. See Table 2 for other useful aria2 options.
Table 2
aria2 Options
Option | Description |
---|---|
--max-overall-upload-limit=SPEED |
Sets the maximum overall speed in bytes, kilobytes, or megabytes. |
--connect-timeout=SECONDS |
Sets the connect timeout in seconds. Default is 60; 0 means no timeout |
--max-file-not-found=NUMBER |
Sets the maximum number of files not found before download fails. |
--max-tries=NUMBER |
Sets number of tries before download fails. 0 means unlimited tries. |
--retry-wait=NUMBER |
Sets the seconds to wait between retries. The default is 5. |
Step 3: Set Up apt-fast
Apt-fast offers the ultimate quick download (Figure 6). This script is not in official Debian or Ubuntu repositories, but you can install it using the script:
/bin/bash -c "$(curl -sL https://git.io/vokNn)"
Once apt-fast is installed, edit /etc/apt-fast.conf
in a text editor (Figure 7). Options include whether to use apt-get
/apt
or the Debian/Ubuntu mirrors and to list your fastest mirrors in a space or comma-separated list. For example:
MIRRORS=( 'http://ftp.debian.org/debian, http://ftp2.de.debian.org/debian, http://ftp.de.debian.org/debian,ftp://ftp.uni-kl.de/debian' )
The same mirrors must also be in your /etc/apt/sources.list
. You can also scroll down the file and check whether other fields, such as the number of connections per command, should be edited. Check, too, that Axel or aria2 is installed.
To use apt-fast, the basic command structure is:
apt-fast install PACKAGE
The command starts by listing all the files that will be installed (Figure 8). When all packages are downloaded, download statistics are displayed (Figure 9). The rest of the output then follows standard apt-get
output as packages are unpacked and installed. Note that the script is only used for package downloads, and that other apt
functions are performed normally.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.