I have two computers at home, my PC and my lenovo S10e netbook, both on Debian. What I’ve installed in one computer it’s likely to be installed in the other one (for instance, OpenOffice.org or Gimp), so every time I upgrade my computers I have to download the same packages twice. I wondered if there was a way to download all packages in one computer and use it as an internal repository….and the answers is yes, by using a cached repository like apt-cacher.
On Debian (or any spin-off like Ubuntu) you can install apt-cacher typing:
aptitude install apt-cacher
Setting the server
In order to set apt-cacher up, you have to edit the /etc/apt-cacher/apt-cacher.conf file. There are several parameters you can change to modify apt-cacher‘s behavior, but the most important to learn is the path_map parameter. By using that parameter you will be defining your internal mirrors. For instance, let’s say you want to set up two mirrors, one for Debian’s (main, contrib and non-free) repositories, and the other one for Debian-Multimedia’s repository. Here’s how you can define them:
path_map = debian http://ftp.us.debian.org/debian/ ; multimedia http://www.debian-multimedia.org
Enabling the service
In order to enable the service at boot time and set the port where the service will be listening, you must edit file /etc/default/apt-cacher as follow:
# set to 1 to start the daemon at boot time AUTOSTART=1 # extra settings to override the ones in apt-cacher.conf EXTRAOPT=" daemon_port=3142 limit=30 "
Importing old packages
If you have already downloaded a quiet few packages and you want to use them, you can import them to apt-cacher. For example, in order to import your .deb files located in /var/cache/apt/archives/, you can use the following command:
/usr/share/apt-cacher/apt-cacher-import.pl -r /var/cache/apt/archives/
The -r option stands for creating hard links or copying the archives (the -s option sometimes doesn’t work due to permission issues).
Restarting the service
Once you have finished to set up your server, you can restart apt-cacher by using its service script:
Setting the clients
Now you have to edit your clients’ repositories file, so they can connect to the new mirrors. For the mirrors you’ve created earlier, add the following lines into the /etc/apt/sources.list file:
deb http://192.168.1.100:3142/debian testing main contrib non-free deb http://192.168.1.100:3142/multimedia testing main
In this example, 192.168.1.100 is the server’s IP address. If you want to use a domain name, you can set a DNS server or just use the /etc/hosts file on each machine (it’s up to you).
Updating and upgrading clients
Now, you are ready to use your new mirrors. As usual, update the packages list and then proceed to upgrade your clients’ system:
aptitude update aptitude safe-upgrade
Repeat client’s steps for every machine you want to connect to the cached server.
apt-cacher comes with a report tool (see below picture) that it’s executed every day via crontab . If you wan to check how much you have saved in bandwidth, you can go to http://localhost:3142/report or http://192.168.1.100:3142/report, or whatever you server’s IP address is. Since I installed apt-cacher, it have shared 366 MB out of 1104.7 MB downloaded…not bad at all :)