aria2 Documentation: Install, Configure & Automate
Everything aria2 can do, in the order you need it: from the first download to a server you control over JSON-RPC. Every command on this page was run on aria2 1.37.0, and the output you see is what it printed.
- 1.37.0current release (2023-11-15)
- 6protocols: HTTP, HTTPS, FTP, SFTP, BitTorrent, Metalink
- 198options
- 36RPC methods
1/4 Get started
What aria2 is
aria2 is a free, open-source download utility for the command line, released under the GPL (version 2 or later). Its program is called aria2c. It downloads over HTTP, HTTPS, FTP, SFTP, BitTorrent and Metalink, and it can fetch one file over several connections and from several sources at the same time, which is why it is often much faster than a browser.
aria2 has no window of its own. You either type commands, or run it in the background as a server that other programs control over JSON-RPC: WebUIs, desktop apps and browser extensions, yt-dlp, scripts. During an HTTP download in our test, aria2 itself used 4.6 MiB of memory (17 MiB counting shared system libraries).
Install aria2
Use your system's package manager: one line installs aria2 and everything it needs. The lines below are for Debian and Ubuntu, Fedora, Arch, macOS with Homebrew, Windows with winget and Android with Termux. Then check the version in a new terminal.
sudo apt install aria2sudo dnf install aria2sudo pacman -S aria2brew install aria2winget install -e --id aria2.aria2pkg install aria2aria2c --versionaria2 version 1.37.0
Step-by-step guides for each system: Windows, macOS, Linux, Android.
On Windows you can also unpack the official zip from the aria2 releases page and add its folder to Path; the official build needs no extra DLLs. Distributions sometimes lag behind: if --version shows something older than 1.37.0, Homebrew, the official zip or a source build gets you the current release.
Build from source
Building is only needed for a newer release than your distribution ships, or for special features. You need a C++11 compiler, autotools and the development packages of OpenSSL or GnuTLS, libssh2, libxml2, zlib, sqlite3 and c-ares. From the git repository:
git clone https://github.com/aria2/aria2.git && cd aria2autoreconf -i./configuremakesudo make install
./configure --help lists the switches, for example --enable-libaria2 to build the library described at the end of this page.
Your first download
Give aria2c a URL and it saves the file in the current folder. -d chooses the folder, -o the file name, and -c continues a download that was interrupted.
aria2c https://example.com/file.isoaria2c -d ~/Downloads -o ubuntu.iso https://example.com/file.isoaria2c -c https://example.com/file.iso
Several URLs on one command line are treated as mirrors of the same file, and aria2 downloads different parts from each. In our test, two hosts finished a file in 6.2 seconds where one host needed 12.2. To download different files, add -Z:
aria2c https://mirror-a.example/file.iso https://mirror-b.example/file.isoaria2c -Z https://example.com/a.zip https://example.com/b.zip
aria2 also accepts magnet links, .torrent files and .metalink files in the same place as a URL.
Many downloads at once: the input file
Put URLs in a text file, one download per line, and pass it with -i. Lines that start with a space hold options for the download above them, written like in aria2.conf. Several URLs on one line, separated by a tab, are mirrors of the same file.
https://example.com/a.iso
dir=/data/iso
out=a-latest.iso
https://mirror-a.example/b.iso https://mirror-b.example/b.iso
checksum=sha-256=HEX
aria2c -i list.txt -j 3
-j sets how many downloads run at the same time (default 5). The same format is used by the session file aria2 writes with --save-session, so a session file is just an input file you can read and edit. Only options marked per download in the options reference are allowed on the indented lines.
Reading the progress line
While it downloads, aria2c rewrites one status line. Here is a real one, from a 47 MiB file over 4 connections:
What each part means
- #90923e
- The first 6 characters of the download's GID, its ID in RPC calls.
- 23MiB/47MiB
- Downloaded so far / total size.
- (48%)
- Progress.
- CN:4
- Open connections. Torrents add SD: seeders connected.
- DL:7.8MiB
- Download speed per second. Torrents add UL: upload speed and the total uploaded.
- ETA:3s
- Estimated time left.
With several downloads running, aria2 switches to a compact form: the total speed first, then up to five downloads, then (+N) for the rest.
aria2c -Z https://example.com/a.bin https://example.com/b.bin[DL:7.9MiB][#2f4d1a 11MiB/47MiB(24%)][#fd1d2f 11MiB/47MiB(24%)]
Two extra blocks can appear: [FileAlloc:#…] while aria2 reserves disk space, and [Checksum:#…] while it verifies a file. Add --summary-interval=0 to hide the periodic summary, or -q for no output at all.
2/4 Download sources
Logins, cookies and headers
Sites that need a login usually check a user name and password, a cookie or a token. aria2 can send all three. We tested each against a server that answers 403 without them; with them, the download went through.
aria2c --http-user=USER --http-passwd=PASS https://example.com/private.ziparia2c --load-cookies=cookies.txt --referer=https://example.com/page https://example.com/file.ziparia2c --header="Authorization: Bearer TOKEN" https://example.com/file.zip
--load-cookies reads the Netscape cookies.txt format that cookie-export extensions produce, and Firefox and Chrome cookie databases. --header can be repeated, one header each time. A 403 or 429 error makes aria2 exit with code 22; the troubleshooting page explains what usually causes it. The easiest way to get cookies right is to let a browser extension hand the download to aria2.
BitTorrent and magnet links
Pass a magnet link (in quotes, because of the &) or a .torrent file. DHT and peer exchange are on by default; local peer discovery (--bt-enable-lpd) and IPv6 DHT (--enable-dht6) are off.
aria2c "magnet:?xt=urn:btih:…"aria2c ubuntu.torrentaria2c --select-file=1,3 demo.torrentaria2c --seed-ratio=1.0 --seed-time=60 demo.torrent
-S lists the files inside a torrent with their index numbers; --select-file downloads only the ones you pick. This is the real output for a three-file test torrent:
aria2c -S demo.torrentMode: multi
Piece Length: 32KiB
Total Length: 362KiB (371,000)
Name: data
Files:
idx|path/length
===+==========================
1|./data/video.mkv
|292KiB (300,000)
2|./data/sub/readme.txt
|0.9KiB (1,000)
3|./data/sub/cover.jpg
|68KiB (70,000)
After a torrent completes, aria2 keeps seeding until the share ratio reaches --seed-ratio (default 1.0) or --seed-time minutes pass. --seed-time=0 stops right away. If a torrent finds no peers, add public trackers with --bt-tracker; our tracker list has a checked list ready to paste.
Metalink
A Metalink file (.meta4 or .metalink) describes one or more files with their size, a checksum and a list of mirrors. aria2 downloads from several mirrors at once and checks the hash at the end.
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
<file name="rand.bin">
<size>50000000</size>
<hash type="sha-256">7d2f…</hash>
<url location="de" priority="1">https://de.example/rand.bin</url>
<url location="jp" priority="2">https://jp.example/rand.bin</url>
</file>
</metalink>
aria2c -M demo.meta4aria2c --metalink-location=jp -M demo.meta4
We downloaded a 50 MB file from a Metalink with two mirrors: it finished in 13.1 seconds, and with a wrong hash in the file aria2 exited with code 32. --metalink-location, --metalink-language and --metalink-preferred-protocol steer which mirrors are used first.
Checksums and integrity
Give the expected hash and aria2 checks the finished file. Supported types include sha-1, sha-224, sha-256, sha-384, sha-512, md5 and adler32.
aria2c --checksum=sha-256=HEX https://example.com/file.iso
When the hash does not match, aria2 exits with code 32 and leaves the file and its .aria2 file on disk, so you can inspect it. Torrents and Metalinks carry their own hashes; -V (--check-integrity) re-checks the pieces of an existing download and fetches only the broken ones.
3/4 Tune and control
Speed and connections
Three options decide how fast a single file downloads: -x (connections per server, up to 16), -s (connections per file) and -k (the smallest piece aria2 splits off, default 20M).
aria2c -x16 -s16 -k1M https://example.com/file.iso
In our test against a server that limits each connection to 2 MiB/s, one connection took 24.1 seconds for 50 MB and 16 connections took 2.3. The third option matters as much as the first two: with the default -k 20M, a 50 MB file is never split into more than 2 parts, whatever -x says. The speed guide has every measurement and when more connections stop helping.
Bandwidth limits
Limits are in bytes per second and take K or M. --max-overall-download-limit caps all downloads together; --max-download-limit caps each one. Uploads to BitTorrent peers have the same two options.
aria2c --max-overall-download-limit=2M -j 3 -i list.txtaria2c --max-download-limit=500K https://example.com/file.isoaria2c --max-overall-upload-limit=100K demo.torrent
All four can be changed while aria2 runs over RPC, so a script or WebUI can slow aria2 down during the day and lift the limit at night. 0 means no limit.
Disk allocation and I/O
--file-allocation decides how aria2 reserves space for a file before writing to it: prealloc (the default) writes the full size first, falloc asks the file system to reserve it instantly, trunc sets the length without reserving, and none does nothing.
aria2c --file-allocation=falloc https://example.com/big.isoaria2c --file-allocation=none https://example.com/big.iso
On ext4, btrfs, xfs and NTFS, falloc is the best choice: it avoids the long pause before large downloads and still prevents fragmentation. On old file systems such as FAT32 it is as slow as prealloc. On an SSD, all modes finished a 2 GiB file within a second of each other in our test. --disk-cache (default 16M) groups small writes in memory.
Resuming and recovery
Next to every unfinished download aria2 keeps a small .aria2 control file that records which pieces are done. Run the same command again with -c and aria2 continues where it stopped. For downloads managed over RPC, a session file restores the whole queue after a restart:
aria2c -c -x16 -s16 https://example.com/big.isoaria2c --input-file=aria2.session --save-session=aria2.session
Two rules from our tests: a kill -9 loses only the progress since the last automatic save (every 60 seconds by default) and never corrupts the file. But deleting the .aria2 file of a multi-connection download and then using -c silently produced a damaged file. Keep the two files together; the .aria2 file guide shows how to recover.
Proxies, IPv6 and network interfaces
--all-proxy sends every download through one proxy; --http-proxy, --https-proxy and --ftp-proxy set one per protocol, and --no-proxy lists hosts that bypass it. aria2 supports HTTP proxies; for a SOCKS proxy, put a local HTTP-to-SOCKS bridge in front.
aria2c --all-proxy=http://127.0.0.1:8080 https://example.com/file.isoaria2c --no-proxy=localhost,.lan https://example.com/file.isoaria2c --disable-ipv6 https://example.com/file.isoaria2c --interface=eth1 https://example.com/file.isoenv | grep -i proxy
aria2 also reads the environment variables http_proxy, https_proxy, ftp_proxy, all_proxy and no_proxy, and they override aria2.conf. If downloads go through a proxy you never configured, check them with the last line above. --disable-ipv6 helps on networks where IPv6 is announced but does not work; --interface binds aria2 to one network card or address.
aria2.conf and which setting wins
Every option can live in a configuration file instead of the command line: the same name without the dashes, one per line. aria2 reads ~/.aria2/aria2.conf (or $XDG_CONFIG_HOME/aria2/aria2.conf) at start; --conf-path chooses another file and --no-conf skips it.
dir=${HOME}/Downloads
continue=true
max-connection-per-server=16
split=16
min-split-size=1M
max-concurrent-downloads=5
file-allocation=falloc
enable-rpc=true
rpc-secret=CHANGE_ME
input-file=${HOME}/.aria2/aria2.session
save-session=${HOME}/.aria2/aria2.session
save-session-interval=60
- 1Built-in defaultsWhat aria2c --help shows as Default.
- 2aria2.confRead once at start.
- 3Proxy environment variableshttp_proxy, https_proxy, ftp_proxy, all_proxy, no_proxy.
- 4Command lineThe last value wins if an option is repeated.
- 5RPC at runtimearia2.changeGlobalOption and aria2.changeOption, for the options that allow it.
Write ${HOME}, not ~, inside the file: aria2 does not expand the tilde there. Comments go on their own line. A misspelled option only prints a warning, so check names in the options reference, or let the config generator write the file for you.
4/4 Automate
Running aria2 in the background
For a download server that is always on, run aria2 with RPC enabled as a service. On Linux, a systemd user service starts it at login and restarts it if it fails:
[Unit]
Description=aria2 download server
After=network-online.target
[Service]
ExecStart=/usr/bin/aria2c --conf-path=%h/.aria2/aria2.conf
Restart=on-failure
[Install]
WantedBy=default.target
systemctl --user enable --now aria2aria2c -D --conf-path=$HOME/.aria2/aria2.conf
The second line is the quick alternative: -D (--daemon) detaches aria2 from the terminal. A daemon changes its working directory to /, so relative paths break: in our test, -d tmp/x saved into /tmp/x. Use absolute paths. On a NAS or server, the Docker guide has a tested container setup.
Remote control with JSON-RPC
--enable-rpc turns aria2 into a server on port 6800. It speaks JSON-RPC over HTTP and WebSocket (ws://host:6800/jsonrpc) and XML-RPC (/rpc). Every call carries the secret as its first parameter, written token:SECRET.
aria2c --enable-rpc --rpc-secret=s3cretcurl -s http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"1","method":"aria2.getVersion","params":["token:s3cret"]}'{"id":"1","jsonrpc":"2.0","result":{"enabledFeatures":["Async DNS","BitTorrent","Firefox3 Cookie","GZip","HTTPS","Message Digest","Metalink","XML-RPC","SFTP"],"version":"1.37.0"}}
Adding a download returns its GID, the 16-character ID you use for every later call:
curl -s http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"1","method":"aria2.addUri","params":["token:s3cret",["https://example.com/file.iso"],{"max-download-limit":"1M"}]}'curl -s http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"1","method":"aria2.tellActive","params":["token:s3cret",["gid","status","completedLength","downloadSpeed"]]}'{"id":"1","jsonrpc":"2.0","result":"54b814f32134da5c"}
{"id":"1","jsonrpc":"2.0","result":[{"completedLength":"1048576","downloadSpeed":"539707","gid":"54b814f32134da5c","status":"active"}]}
A wrong or missing secret is refused:
curl -s http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"1","method":"aria2.getVersion"}'{"id":"1","jsonrpc":"2.0","error":{"code":1,"message":"Unauthorized"}}
aria2 1.37.0 has 33 aria2.* methods plus system.multicall, system.listMethods and system.listNotifications. Over WebSocket, aria2 also pushes six notifications, such as aria2.onDownloadComplete, so a client does not need to poll. Values in option objects are strings. To try calls without writing code, use our online WebUI. Every method, with real requests and replies, is in the JSON-RPC guide.
Event hooks
aria2 can run a program when a download starts, pauses, stops, completes or fails, and when a torrent finishes downloading (before seeding). Each command receives three arguments: the GID, the number of files and the path of the first file.
#!/bin/sh
echo "$(date) finished $3" >> "$HOME/aria2-done.log"
chmod +x done.sharia2c --on-download-complete=$PWD/done.sh https://example.com/file.isoargs: 3 | 1=f9bfdbfe450c75f3 | 2=1 | 3=/home/me/out/rand.bin
The output line is what our test hook received. Give the full path to the script and make it executable. The hooks are --on-download-start, --on-download-pause, --on-download-stop, --on-download-complete, --on-download-error and --on-bt-download-complete. The Docker guide uses one to move finished files.
Security and encryption
An RPC server can download anything to your disk and run hook scripts, so treat port 6800 like a password-protected admin panel. Always set --rpc-secret, keep --rpc-listen-all off unless another device on a trusted LAN or VPN must connect, and never forward the port to the internet.
aria2c --enable-rpc --rpc-secret=$(openssl rand -hex 16)aria2c --enable-rpc --rpc-secure --rpc-certificate=cert.pem --rpc-private-key=key.pem --rpc-secret=s3cretaria2c --ca-certificate=/etc/ssl/certs/ca-certificates.crt https://example.com/file.iso
With --rpc-secure, aria2 serves RPC over TLS itself; in our test it answered on https:// and ignored plain HTTP. A reverse proxy such as nginx is the other option. For downloads, aria2 checks server certificates against the system CA store; --ca-certificate points it elsewhere, and --check-certificate=false turns the check off, which you should only do for a host you trust.
Files aria2 creates
file.aria2: the control file next to an unfinished download. Deleted when it completes. See the .aria2 file guide.- Session file (
--save-session): unfinished downloads with their options, in input-file format. dht.datanddht6.datin~/.aria2/(or$XDG_CACHE_HOME/aria2/): known DHT nodes, so torrents find peers faster next time.- Cookie file (
--save-cookies): cookies in Netscape format. - Log (
--log): off by default;--log-level=infoordebugfor detail. .torrentor.meta4files: saved only when you ask with--bt-save-metadataor--rpc-save-upload-metadata.
Exit codes
When aria2c finishes, its exit code tells a script what happened. With several downloads, it is the code of the last error. The codes marked with a link have a step-by-step fix on the troubleshooting page.
| Code | Meaning |
|---|---|
| 0 | All downloads succeeded |
| 1 | Unknown error (also used for connection, TLS and RPC-port errors) |
| 2 | Timeout |
| 3 | Resource not found |
| 4 | "Resource not found" reached --max-file-not-found |
| 5 | Too slow: --lowest-speed-limit |
| 6 | Network problem |
| 7 | Unfinished downloads when aria2 was stopped (Ctrl+C) |
| 8 | The server does not support resume, but resume was required |
| 9 | Not enough disk space |
| 10 | Piece length differs from the .aria2 file |
| 11 | aria2 was already downloading the same file |
| 12 | aria2 was already downloading the same torrent |
| 13 | The file already exists |
| 14 | Renaming the file failed |
| 15 | Could not open an existing file |
| 16 | Could not create or truncate the file |
| 17 | File I/O error |
| 18 | Could not create the directory |
| 19 | Name resolution failed |
| 20 | Could not parse the Metalink document |
| 21 | FTP command failed |
| 22 | Bad or unexpected HTTP response (also 403, 429) |
| 23 | Too many redirects |
| 24 | HTTP authorization failed |
| 25 | Could not parse a bencoded (.torrent) file |
| 26 | .torrent file corrupted or incomplete |
| 27 | Bad magnet URI |
| 28 | Bad option or option value |
| 29 | Server temporarily overloaded or in maintenance (503) |
| 30 | Could not parse the JSON-RPC request |
| 31 | Reserved, not used |
| 32 | Checksum validation failed |
Units and handy tricks
Sizes and speeds take K and M, where 1K is 1024 bytes. There is no G, and decimals are rejected; aria2 stops with exit code 28:
aria2c --max-download-limit=500K URLaria2c --max-download-limit=1.5M URLException: … errorCode=28 We encountered a problem while processing the option '--max-download-limit'.
-> … Bad or negative value detected: 1.5M
- Repeat an option and the last value wins; the command line beats aria2.conf.
- Turn an on/off option off with
--name=false, not--name false. --input-file=(empty) ignores a session file set in aria2.conf for one run.--dry-runchecks that a URL works without downloading it.aria2c --help=#httplists the options with one tag;aria2c --help=splitthe ones whose name contains a word.
libaria2 for developers
aria2 can be built as a C++ library (./configure --enable-libaria2), so a program can run downloads without starting aria2c or talking RPC. The API is in aria2/aria2.h; one session per process. This minimal program downloads one file:
#include <aria2/aria2.h>
int main() {
aria2::libraryInit();
aria2::SessionConfig config;
aria2::Session* session = aria2::sessionNew(aria2::KeyVals(), config);
aria2::addUri(session, nullptr, {"https://example.com/file.iso"}, aria2::KeyVals());
while (aria2::run(session, aria2::RUN_ONCE) == 1) {}
aria2::sessionFinal(session);
aria2::libraryDeinit();
}
g++ -std=c++11 example.cc -laria2 -o example./example
We compiled it against libaria2 1.37.0 on Ubuntu 24.04 and it downloaded a 50 MB test file. The aria2 repository has two full examples, examples/libaria2ex.cc and a wxWidgets GUI, libaria2wx.cc. For most projects, JSON-RPC is simpler and works from any language.