How to Manage and Speed-up Your Large File Downloads with Aria2

How to Manage and Speed-up Your Large File Downloads with Aria2
Photo by Mathew Schwartz / Unsplash

Introduction

In this tutorial, you will learn how to use Aria2 to handle multiple downloads with many files over different protocols. Aria2 is a command-line tool that can be controlled via JSON-RPC and XML-RPC interfaces, and supports the following protocols:

  • HTTP/HTTPS
  • FTP
  • SFTP
  • Metalink and BitTorrent with Fast, DHT, PEX and MSE/PSE extensions & WEB seeding

Aria2 can be configured from the command line, but also supports configuration files (/etc/aria2.conf or ~/.aria2/aria2.conf) and use ~/.netrc file for authentication credentials. The application can handle downloading multiple files over different protocols using command arguments. And the memory usage is very low - generally less than 10 MB RAM!

Prerequisites

Before you begin, please make sure you have:

  • A Linux bare metal instance, virtual machine or Docker container
  • Basic knowledge of Linux command line

Step 1 - Installation of Aria2

The application is available in many Linux distributions, choose the right way for your package manager below:

  • For Red Hat Enterprise Linux and similar (Fedora, Centos):
# dnf install aria2
  • For Debian-based Linux distributions (Ubuntu):
# apt install aria2
  • For openSUSE:
# zypper install aria2
  • For Archlinux:
# pacman -S aria2

If your OS is different, always check the official documentation.

Step 2 - Getting Familiar with Basic Commands

For example, let's download Ubuntu 24.10 via torrent and 24.04 via HTTPS:

aria2c https://releases.ubuntu.com/24.10/ubuntu-24.10-desktop-amd64.iso.torrent https://www.nic.funet.fi/pub/mirrors/releases.ubuntu.com/24.04.1/ubuntu-24.04.1-desktop-amd64.iso

As you can see, it's possible with the single command.

If you want to download a part of a file, aria2 can help you as well:

aria2c --header="Range: bytes=1-1024" https://download.fedoraproject.org/pub/fedora/linux/releases/41/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-41-1.4.iso

The above command downloads the first kilobyte of the Fedora 41 iso image. If you're on a corporate network, the proxy is often a requirement. With aria2, the next command can be used to download through a proxy:

aria2c -c --http-proxy="http://proxy.corp.com:8080" https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4

To continue the download when network problems occur, you can use the -c flag.
Time to dive deeper and look at the more advanced aria2 options:

  • --header="Referer: https://example2.com" - use custom referer
  • --max-overall-download-limit=100K - limit download speed to 100 Kbps
  • --max-tries=3 - specify a maximum number of retries
  • -i urls.txt - download the whole list of files, there should be one link per line.
  • -o new_file.txt - rename the output file name to new_file.txt
  • -d /tmp - set the target directory to /tmp/
  • --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0" - set User Agent to Firefox
  • --file-allocation=none - disable file allocation
  • --timeout=100 - set the download timeout to 100 seconds
  • --show-files ubuntu.torrent - show all files available for download
  • --select-file=1-2 ubuntu.torrent - select the first two files from the Ubuntu torrent file to download.

Yt-dlp and Faster Multi-Threaded Downloads

Multiple connections are often helpful to download files faster. It depends on many factors: ISP limitations, web server limitations, network load status and more. The Aria2 command for downloading a file with 8 connections looks like this:

aria2 -x 8 https://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_h264.mov

More complicated example - downloading a playlist from YouTube. To accomplish this task, you will need to install the yt-dlp tool, assuming Python 3 is already installed:

pip install yt-dlp

For example, let's download the LF Research playlist by Linux Foundation from YouTube:

yt-dlp --external-downloader aria2c --external-downloader-args '-x 8 -j2'  https://www.youtube.com/playlist?list=PLseEp7p6EwiY1PaNdbBdGVOowGKiYhJiG

All options explained:

  • --external-downloader aria2c - use aria2 as downloader
  • --external-downloader-args - pass the arguments to aria2
  • -x 8 - number of threads for each download
  • -j 2 - number of simultaneous downloads

The Configuration File

Aria2 checks its configuration file in the following places:

  • /etc/aria2.conf - global configuration
  • ~/.aria2/aria2.conf - local configuration only

An example of a configuration file with a configuration that is optimized for better performance is provided below:

# /etc/aria2.conf

# Enable RPC on all interfaces over HTTPS, set the listen port and token  
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
rpc-secret=YOUR_TOKEN

# Increase the maximum number of concurrent downloads from default of 5 to 8
max-concurrent-downloads=8

# Increase number of connections per server, default is 1
max-connection-per-server=16

# Do not split files smaller than 2 GB
min-split-size=2048M

# Download a file using 10 connections
split=10

# Make 10 attempts to download a file and give up
max-tries=10

# Timeout in 600 seconds to downoad a file when connection is established
timeout=600

Web interface

There are several web interface projects for Aria2:

The most active project is AriaNg, the pure classic web UI, written in pure HTML and JavaScript:

AriaNg desktop version

Looks pretty comfortable, access to the settings of each download with one click and there's also a traffic visualization.

The mobile version offers the same features with a well optimized interface for smartphones:

AriaNg mobile version

Conclusion

Aria2 is a top-notch tool for downloading files from the Internet. It may not be the best choice for grabbing two or three images from a website, but gigabytes or terabytes of data - that's what this application is designed for. Multithreading support, download resume, built-in splitting and peer-to-peer download support, web UI for remote installations and resuming downloads from broken connections all make Aria2 a desirable choice as the default download manager on the desktop, headless server or in the cloud.

Read more