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:
- 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.
To install apt-cacher simply install the package (or click the link below):
sudo aptitude install apt-cacher
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
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.
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:
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.