How to clear apt-cacher cache – Ubuntu 14.04 – apt-cacher: Cache Full

We have a server running apt-cacher to help cache Ubuntu repositories.  However, after about 2 years of usage the disk on the server has filled up.  I discovered this after trying to update my Ubuntu desktop and got the following error:

503  apt-cacher: Cache Full

Here is how to clear the apt-cache cache.

sudo service apt-cacher stop
sudo rm -rf /var/cache/apt-cacher-ng/
sudo mkdir -p /var/cache/apt-cacher-ng/{headers,import,packages,private,temp}
sudo service apt-cacher start

How to change /etc/apt/sources.list to use local apt-cache server in a single sed command

I’ve just installed an Ubuntu apt-cache server on our local network to speed up downloading packages each time we install or upgrade an Ubuntu computer. However, changing all the /etc/apt/sources.list file for every computer in the office is a real pain. Here is a simple command using sed which does this automatically for you:

The apt-cache server in our office is 192.168.2.2 but obviously change this to suit your needs. Note: the command can be run multiple times and won’t change the result:

 sed -i '/192.168\|^#/! s/http:\/\//http:\/\/192.168.2.2:3142\//g' /etc/apt/sources.list 

Hope this helps someone.