Saving Bandwidth with apt-cacher-ng

Nathan Osman's Gravatar

Nathan Osman
published Aug. 25, 2013, 1:10 p.m.

At my home, we have three computers - all of which are running Ubuntu 13.04. Every time new package updates are released, each computer must download the packages directly from a nearby mirror and install them. This might not be a problem if I had a really fast Internet connection and relatively few packages installed. However, I have a ton of packages installed and a fairly slow Internet connection. I needed a way to ensure that each package was only downloaded once.

Enter apt-cacher-ng.

This tool (once installed) will cache the packages that are downloaded and will serve them to other machines on the network that are configured to use it. I don't keep any of my computers running all of the time, so I needed some way of ensuring the cache would always be available for whatever needed it.

Enter my Raspberry Pi.

Setting It Up

Setting up the server is incredibly simple. I connected to my Pi via SSH and ran the following command:

sudo apt-get install apt-cacher-ng

That's it for the server. Next, for each client you will need to create a file named /etc/apt/apt.conf.d/02proxy and insert the following contents (you can do this by opening a terminal and running gksu gedit /etc/apt/apt.conf.d/02proxy):

Acquire::http { Proxy ""; };

Note that you will need to change the IP address to that of the server that apt-cacher-ng is running on.

Once this is complete, simply run apt-get update or apt-get upgrade as you would normally and each package will automatically be downloaded and stored in the cache. Then when you run the same commands on another computer, the packages will be returned from the cache instead of being downloaded again.