Yao Lirong's Blog

Install and Configure Aria2 on WSL

2021/06/28

Tutorial

  1. Install Aria2c: sudo apt install aria2c

    and a web-based GUI: AriaNg

  2. Create configuration files:

    1
    2
    3
    mkdir ~/.aria2
    touch ~/.aria2/aria2.session #用于保存日志
    touch ~/.aria2/aria2.conf #创建配置文件

    A template for “aria2.conf” can be downloaded from aria2c.com. You should change the dir field to be download path, change input-file and save-session to be the path of aria2.session. aria2.conf doesn’t support environment variable, so everything is at best written in absolute path.

  3. Run Aria2c with this configuration: aria2c --conf-path=/home/<username>/.aria2/aria2.conf. It will remember this as its configuration file and use it to start the service from now on. We can also add argument -D so Aria2c runs as daemon in the background. (Since the aria2c’s default configure file path is in ~/.aria2/, we don’t really need the --conf-path argument; but use it to specify a conf path if you put it somewhere else)

  4. 设置 aria2c 开机自动启动:编写脚本 myStartUp.sh 并放入 /etc/init.d/. (Remember to change its privilege to everyone)

    1
    2
    3
    4
    5
    #!/bin/bash

    #Short-Description: My Startup Services

    aria2c -D --conf-path=/home/<username>/.aria2/aria2.conf

    More on Start Service on WSL startup, refer to this answer

Caution

On WSL, when you start aria2 service the first time, note: (full command means the above command with --conf-path, but since our conf path is the same as default path, we can take )

  1. use the full command aria2c --conf-path=/home/<username>/.aria2/aria2.conf and don’t start it in the background with -D.
  2. start it immediately after Windows is booted, before you open anything else or tweak anything

Anything else than this full command or use this full command some time after Windows boot could cause problem. The problem is showing “Exception: [SocketCore.cc:312] errorCode=1 Failed to bind a socket, cause: Permission denied” even though no process is using port 6800. The reason for this problem is not clear.

After staring aria2 once with the full command, we can shut it down and then start it in the background with aria2c -D --conf-path=/home/<username>/.config/aria2/aria2.conf. Now everything will work fine.

Reference

  1. Linux中配置Aria2 RPC Server
  2. linux设置开机自启动
  3. WSL 服务自动启动的正确方法
CATALOG
  1. 1. Tutorial
  2. 2. Caution
  3. 3. Reference