Thursday, September 15, 2011

Accelerate download of apt-get via aria2 in Ubuntu


Need for download accelerator

In ubuntu software installation is done via apt-get or synaptic. Both of them download the required packages from the repositories via wget. While wget is great, it doesn't accelerate the download. After a bit of research (read googling) I found the script apt-fast script written by Matt Parnell and the apt-axel script written by freshmeat user jespino. Both of these scripts use axel (a command line download accelerator) to accelerate the download of apt-get.
Unfortunately I couldn't configure axel for proxy support. Since I was behind proxy, this was a major deal killer. Finally after a bit of googling I found that aria2, another command line download accelerator supported proxy. So I re-wrote the apt-fast script to use aria2 instead of axel and named it apt-aria2 (Not very original name I admit).

Requirements

You off-course need to install aria2
sudo apt-get install aria2

Installation

Installation is pretty easy. Just download the apt-aria2 script, make it executable and put it in your $PATH.
chmod +x apt-quick
sudo cp apt-quick /usr/local/bin/
Note that putting the apt-aria2 script in $HOME/bin will not work even though it is in the $PATH. As a user you will be able to access it. However using the sudo command you won't be able to use the script. This is probably because $HOME/bin is not in the $PATH of the superuser, but only the user.

 

Proxy settings

Proxy setting is same as proxy setting for apt-get. Open or create the apt.conf file
sudo gedit /etc/apt/apt.conf
and copy the following lines
## Proxy settings
Acquire::http::proxy "http://username:password@your.proxy:port/";
Acquire::ftp::proxy "ftp://username:password@your.proxy:port/";
Acquire::https::proxy "https://username:password@your.proxy:port/";
where you should replace the username, password, proxy and port by your own username, password, proxy and port respectively. Duh! In case of couple of softwares (eg.: flashplugin-installer and ttf-mscorefonts-installer) download of the actual software is always via wget. In that case one should also configure the wget proxy. Open the wgetrc file
sudo gedit /etc/wgetrc
Scroll down to the proxy lines and replace them by
https_proxy = http://username:password@your.proxy:port/
http_proxy = http://username:password@your.proxy:port/
ftp_proxy = http://username:password@your.proxy:port/
use_proxy = on

Usage

Usage is pretty much the same as apt-get. A few examples are as follows:
sudo apt-aria2 install package1 package2
sudo apt-aria2 update
sudo apt-aria2 upgrade
sudo apt-aria2 remove package1
sudo apt-aria2 purge package1
In case of update, it directly uses apt-get. In other cases where one has to download the software (Eg.: install, upgrade, dist-upgrade) it downloads the software via aria2 and installs in via apt-get.

 

Multiple simultaneous downloads

Apt-get always locks the process, so at any given time one can only use one instance of apt-get. However using the ``-d" (download-only, no installation) option of apt-aria2, one can use multiple instance of apt-aria2. Once download is complete for all packages, one then has to use apt-aria2 again without the ``-d" option, to install the same packages. Eg:
## In terminal 1
sudo apt-aria2 -d install package1 package2
## In terminal 2
sudo apt-aria2 -d install package3
## After all downloads are complete
sudo apt-aria2 install package1 package2 package3
However, one should use the ``-d" option with caution. The packages being installed simultaneously
  • shouldn't have the same dependencies
  • shouldn't conflict with each other.

Known bug

If more than one packages are being installed, then once apt-aria2 starts, its difficult to stop the download by pressing ``Ctrl+c". This is because, as soon as one presses ``Ctrl+c", it stops the current download and starts downloading the next in line. I can't seem to write the script which would stop it once and for all. If someone knows the solution to this let me know.
This document was generated via LATEX2html.

No comments:

Post a Comment