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 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:\/\/\//g' /etc/apt/sources.list 

Hope this helps someone.

Leave a Reply