Every bit of software on a Linux system needs to be as up to date as possible. It's the best practice against hackers and other security related risks. Sometimes, updates also add functionality and improve the stability of programs. On Ubuntu systems, the update process is completed through APT (Advanced Packaging Tool), which is a package management system initially made for Debian Linux and later used by its derivatives as well. Once the update command has been executed, APT will download the latest version of the installed packages, from an official repository.
However, if you have a local network of computers running the same distribution, you'll need to think about setting a repository cache on your network so that once an updated package is downloaded from an official repository, all other machines will download it from a local server. This way, common packages won't be downloaded more than once from official repositories, the rest of the computers will download their updates at maximum speed (LAN) and your Internet bandwidth will be saved.
If this is your situation as well, here is what you'll need to do. First, you need to configure a local machine to act as a repository cache, while the rest of the local computers will use it as a repository.
Installing Apt-Cacher
- Run the following command on the local machine that will act as a repository cache:
- Ignore the error about not being able to start apt-cacher.
Configuring Apt-Cacher
- Open /etc/apt-cacher/apt-cacher.conf with your favorite text editor and set it according to your needs. Every directive is explained in detail so there's no need for me to explain them here.
- Activate Apt-Cacher: open /etc/default/apt-cacher with your favorite text editor and set AUTOSTART to 1. This will also start Apt-Cacher on each system boot.
- Restart Apt-Cacher:
Setting up the LAN clients
- You now have to edit the file /etc/apt/sources.list on every computer on the network so they will use the local repository-cache machine, not the Internet official repository. To do that, open the sources.list file and edit it to look like this:
deb http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy main restricted
deb-src http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy main restricted
#ubuntu updates repository
deb http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy-updates main restricted
deb-src http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy-updates main restricted
#ubuntu security updates repository
deb http://10.10.0.1:3142/security.ubuntu.com/ubuntu edgy-security main restricted
deb-src http://10.10.0.1:3142/security.ubuntu.com/ubuntu edgy-security main restricted
NOTE: The IP 10.10.0.1 is an EXAMPLE. Replace it with the correct IP address of the machine running apt-cacher. Moreover, if you have more entries in your source.list, you need to prefix each one with the local IP of the machine running apt-cacher and the specified port.
- More examples:
deb-src http://archive.ubuntu.com/ubuntu/ edgy universe
becomes:
deb-src http://10.10.0.109:3142/ro.archive.ubuntu.com/ubuntu/ edgy universe
- Now that everything is set, you need to resynchronize the package index files from their sources. To do this, run the command:
Automatically update systems every day
- Create a file called auto-update.sh in /usr/bin:
- Change its permissions to root:
sudo chown root.root /usr/bin/auto-update.sh
- Open the file /usr/bin/auto-update.sh with your favorite directory and add the following code:
touch /var/log/auto-update.log
apt-get clean > /dev/null
apt-get autoclean > /dev/null
apt-get update >> /var/log/auto-update.log
apt-get -y upgrade >> /var/log/auto-update.log
exit
- Execute the following command to edit the crontab for user root:
- A text editor will be opened and you'll need to add the following line AT THE END so the script will be executed every day at 14:30:
Generating reports
- Set the generate_reports directive to 1 in /etc/apt-cacher/apt-cacher.conf.
- The report is generated once a day, but if you need it at a certain time, you can force it by running:
















