Commands.page Logo

How to Run aria2c as a Background Daemon on Ubuntu

This guide explains how to configure aria2c to run continuously as a background daemon on Ubuntu. You will learn how to install the software, create a configuration file for persistent settings, and set up a systemd service to manage the process automatically. By following these steps, you can ensure your downloads continue even after you log out or close the terminal.

Install aria2

Begin by updating your package list and installing aria2 using the apt package manager. Open your terminal and run the following commands:

sudo apt update
sudo apt install aria2

Create the Configuration Directory and File

You need a configuration file to define how aria2c behaves when running as a daemon. Create the directory and the configuration file in your home folder:

mkdir -p ~/.aria2
touch ~/.aria2/aria2.conf

Open the configuration file with a text editor like nano:

nano ~/.aria2/aria2.conf

Add the following basic settings to the file. This enables the RPC interface, sets the download directory, and configures logging:

dir=/home/your_username/Downloads
input-file=/home/your_username/.aria2/aria2.session
save-session=/home/your_username/.aria2/aria2.session
save-session-interval=60
enable-rpc=true
rpc-listen-all=true
rpc-listen-port=6800
continue=true
max-connection-per-server=5
min-split-size=10M
follow-metalink=true
follow-torrent=true

Replace your_username with your actual Ubuntu username. Save and exit the file.

Create the Systemd Service File

To run aria2c as a background daemon, you must create a systemd service unit file. Create a new file at /etc/systemd/system/aria2c.service:

sudo nano /etc/systemd/system/aria2c.service

Paste the following configuration into the file:

[Unit]
Description=Aria2c Download Manager
After=network.target

[Service]
Type=simple
User=your_username
ExecStart=/usr/bin/aria2c --conf-path=/home/your_username/.aria2/aria2.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

Ensure you replace your_username with your actual username in both the User and ExecStart lines. Save and close the file.

Enable and Start the Service

Reload the systemd manager configuration to recognize the new service file:

sudo systemctl daemon-reload

Enable the service to start automatically on boot and start it immediately:

sudo systemctl enable aria2c
sudo systemctl start aria2c

Verify the Daemon Status

Check the status of the service to ensure it is running without errors:

sudo systemctl status aria2c

If the service is active, aria2c is now running in the background. You can interact with it using an RPC client or by adding tasks to the session file.