Apt-Cacher: Revisited

By | 2009/09/06

Apt-Cacher Ubuntu : Revisited

I’m sure that I’ve mentioned a number of times that the bandwidth speeds at my house are pretty horrible. It is very frustrating to have such a limited pipe considering the amount of work I do that requires bandwidth. Based on this limitation I regularly come up with ways to conserve and cache. One of these methods (which I have blogged about in the past) is apt-cacher.

Apt-Cacher is a method by which you can centrally cache and share packages already stored within your network. It also allows the option of caching any downloaded packages in the future. This allows me to download a package once and transparently share it with an unlimited number of machines within my network. This way I only use my Lanwidth (LAN-bandwidth), and not my limited WAN connection.

Apt-Cacher can be installed and configured network wide in five simple steps. These steps are:

  • Install
  • Autostart daemon
  • Configure ACL
  • Import current packages
  • Configure Clients

To be honest, the first four steps are finished in just a few minutes. The last step of configuring your clients can take longer. The amount of time depends on how many clients you have.

Install

To install apt-cacher simply install the package (or click the link below):

sudo aptitude install apt-cacher

Autostart daemon

If you want the apt-cacher daemon to autostart at boot you’ll need to change a single value in the config:

sudo sed -i.orig 's/AUTOSTART=0/AUTOSTART=1/' /etc/default/apt-cacher
sudo /etc/init.d/apt-cacher restart

 

Configure ACL

This step is optional. By default apt-cacher will allow access to any IP. If you would like to limit access to your cache from a specific subnet or other specific addresses you’ll need to change the values for allowed_hosts and denied_hosts in the /etc/apt-cacher/apt-cacher.conf.

Import current packages

You’ll likely want to import the current packages that you have in your machine’s package cache. This can be done using the command:

sudo /usr/share/apt-cacher/apt-cacher-import.pl -s /var/cache/apt/archives/

At this point this machine will have the ability to share any packages that it has previously downloaded as well as any package that it (or any client) will download in the future. The only requirement to begin using this cache throughout your network is configuring the clients to use it.

Configure Clients

To configure your clients to use your cache you can simply add a line to your apt.conf file, telling the client to use the cache server. To do this add the following line to your /etc/apt/apt.conf file, replacing the IP with your own:

Acquire::http::Proxy "http://192.168.0.30:3142"

You’re now done. As long as your apt-cacher is accessible your client will look there for cached packages.

If anyone knows of a method to allow for multiple proxy entries I would be very interested. For example, if this were configured on a laptop and the apt-cacher were not accessible, I would like the client to transparently try the next entry in a list. This is something available in many other package managers, I would hope Debian based distributions would support the same.

5 thoughts on “Apt-Cacher: Revisited

  1. zelut Post author

    I wonder what the difference is between the Debian and Ubuntu package. I'm running mine on a Debian server and I don't have that problem.

  2. Manish Mahabir

    what about aptzeroconf?

  3. Mark S

    apt-cacher-ng is an alternative that works on basically the same system but doesn't hose the server resources. I've recently changed over and prefer the nice neat looking web interface on the ng version

  4. Skip Da Shu

    I’ve been running apt-cacher on a Xubuntu machine for some time (maybe late 2007) but I don’t have this file:

    “To do this add the following line to your /etc/apt/apt.conf file,…”

    Instead I have this line in a file called 01proxy that is in /etc/apt/apt.conf.d/

Comments are closed.