When running multiple machine with the same distribution, it is interesting to set up a repository cache on your network so that once a package is downloaded from an official repository, all other machines will download it from your local area network.
Having different machines running the same linux distribution, it becomes interesting to set up a repository cache somewhere on your network. This way, you won’t download common packages more than 1 time from official repositories.
Here is the situation, we have one machine called
repository-cache, this machine is going to act as the repository cache, basically, any other machines in your network is going to use it as a repository.
1. Getting started
As usual, you need to install the required packages in the first place. So type in a terminal:
$sudo apt-get install apt-cacher
Once this is done, it is time to get into the configuration files in
2. Configuring Apt-Cacher
So now, open apt-cacher’s main configuration file:
/etc/apt-cacher/apt-cacher.conf and start editing it according to your settings.
The default port apt-cacher is running on is
port 3142. You might want to change this value accordingly to your needs.
allowed_hosts: by default, all host are allowed to use the repository cache. You can change this value if you want to only allow certain host. In my case, I want to allow my LAN 192.168.1.0/24 and localhost (both 127.0.0.1 and 127.0.1.1 on ubuntu boxes), so I changed the value to:
as 127.0.0.1 is always allowed, it was not necessary to add 127.0.0.1
generate_reports: This directive makes apt-cacher create a report on how efficient your cache was on a daily basis. Default is 1, if you want to disable this, set it to 0
path_map: This is an interesting directive. Here you can define different aliases for different repository host. For my ubuntu edgy box, my path_map looks like this:
path_map = debuntu repository.debuntu.org ; ubuntu archive.ubuntu.com/ubuntu; ubuntu-updates archive.ubuntu.com/ubuntu ; ubuntu-security security.ubuntu.com/ubuntu
Let me explain that bit. Here I created mappings from names:
Now, in order to access a specific repository, we simply need to append the mapping name to our cache repository server, like:
So, for instance, we can access debuntu repository through
http://repository-cache:3142/debuntu and ubuntu secutiry repository through
2.2. Activating apt-cacher to start
In order to start, apt-cacher needs to be activated from
/etc/default/apt-cacher. So open
/etc/default/apt-cacher and set
AUTOSTART to 1:
Now restart apt-cacher:
$sudo /etc/init.d/apt-cacher restart
Now that apt-cacher runs, it is time to update all our clients /etc/apt/sources.list files so every host on the network will use our