I have three Ubuntu systems and I wish to minimize download bandwidth by setting up a cache of downloaded packages. (With only three systems, it's not worth setting up a full mirror).
apt-cacher-ng
sounded perfect for this, but it doesn't work as I expected after setting up a trial with 1 server and 1 client.
When I install software on the client, it works as expected - packages are downloaded to the server and stored in the server's cache.
But when I install software on the server, the packages are not cached.
This kind of ruins apt-cacher-ng
's utility for me - with only two systems, I will end up downloading the software packages twice anyway (like for kernel updates, etc). I would like it to cache the packages downloaded to be installed on the server; for me, there is a huge overlap between these packages and what the clients will request.
Is there a way to get apt-cacher-ng
to cache the packages which are downloaded to be installed on the server?
To get the server machine to go through the cache, it also needs to be set up as a caching (
apt
) client. When you follow theapt-cacher-ng
instructions for the server machine, you need to perform the steps for setting it up as both a caching (apt-cacher-ng
) server and a caching (apt
) client. Your unexpected situation looks like this:In the case of the server, set its
Acquire::http::Proxy
tohttp://localhost:3142
instead of how the client machines set the proxy to be the server's hostname. This works and is more reliable. After this, the situation is as expected:The 4 concepts of server machine (machine that runs both
apt
andapt-cacher-ng
), client machine (machine that runs justapt
), caching server (apt-cacher-ng
), and caching client (apt
) should not be confused. It's simple on the client machines. But on the server machine, its own caching client (apt
) is not modified by the installation ofapt-cacher-ng
.apt-cacher-ng
is a separate thing that you run, and setting the proxy tolocalhost
will not cause a loop. In fact, the proxy must be set so that the server machine's caching client (apt
) goes through the caching server (apt-cacher-ng
) (coincidentally running on the same machine) in order to work as expected.Supplementary answer with some tips for anyone who wants to do this:
/etc/apt/apt.conf.d
to set up the proxy is world-readable or you will have to usesudo
any time you do anapt policy
.apt-cacher-ng
.apt-mirror
, but I still have some testing to do on this.