deb package cache

18 Nov 2011

Update: I created a script who automate the process described in this post.


apt-cacher-ng is a kind of deb repository proxy, it caches deb packages on demand between the computer who share the cache, it’s a great alternative for small environments. There are other alternatives, such as apt-cacher, apt-proxy and debmirror but those solutions can take more space or be harder to setup, so I won’t talk about them.

In the client side, there exist mainly two ways of taking advantage of such services, squid-deb-proxy and manual configuration. The first one uses zeroconf to detect and use deb proxies whenever they’re available and the second one, well, is manual and works by adding a string to /etc/apt/apt.conf.d/01apt-cache describing the proxy url. On this post I’ll talk about squid-deb-proxy.


[+] In the server side (which can be client at the same time):

$ sudo apt-get install apt-cacher-ng squid-deb-proxy-client
$ sudo wget -O /etc/avahi/services/apt-cacher-ng.service
$ sudo service apt-cacher-ng restart

[+] In the client side:

$ sudo apt-get install squid-deb-proxy-client

After executing these commands the apt-cacher-ng server will announce itself to all computers in the local network, and clients machines will be able to autoconfigure their apt preferences depending of whether they see an apt-cacher-ng server or not. Pretty cool 😊


Import packages

Old packages (downloaded before setting up apt-cacher-ng) can be imported by executing:

$ sudo mkdir -pv -m 2755 /var/cache/apt-cacher-ng/_import
$ sudo mv -vuf /var/cache/apt/archives/*.deb /var/cache/apt-cacher-ng/_import/
$ sudo chown -R apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng/_import
$ sudo apt-get update

And going to http://localhost:3142/acng-report.html where a ‘Start import’ button will show up:

Delete apt-cacher-ng

This setup can be destroyed at any time by running:

[+] In the server:

$ sudo apt-get remove apt-cacher-ng squid-deb-proxy-client
$ sudo rm -rf /var/cache/apt-cacher-ng

[+] In the clients:

$ sudo apt-get remove squid-deb-proxy-client

Happy caching 😏