Save Bandwidth With Multiple Machines with Apt-Cacher : Ubuntu (6.10)

By | 2007/01/08

Over the holidays I was visiting my parents and helping my brother with his Ubuntu system. One of the biggest drawbacks of heading up that way for a visit is leaving the fiber-optic comforts of home and heading up to DSL villa. I swear its like rewinding a decade and hearing the hellish dial-up noises all over again!

In any event, I was helping my brother update his Ubuntu machine and was getting tired of seeing the estimated download time hover around 18hrs! It was about that time that I got to thinking… “my laptop is up to date. There should be a way for him to simply download the updates from my machine over the LAN.” After some Google magic I came across Apt-Cacher and a cure was found!

“Apt-cacher performs caching of .deb packages which have been downloaded by local users. When a package is requested, the cache checks whether it already has the latest version, in which case it sends the package to the user immediately. If not, it downloads the package while streaming it to the user at the same time. A local copy is then kept for use by other users.”

Apt-Cacher will allow you to centrally cache any updates or installed packages on a central machine and help you save bandwidth. No matter if you have two Ubuntu machines or twenty, as far as your bandwidth is concerned your ISP will only think you have one! Below are steps for setting up Apt-Cacher.

First, of course, we’ll need to install it (it only needs to be installed on one central machine).

sudo aptitude install apt-cacher

To test that it is installed correctly you can try visiting the address below:

http://[localhost]:3142/ or http://[LOCAL.IP]:3142/

If you see the Apt-Cacher page the server end of things are setup. There are a few other things you can tweak, and you’ll probably want to take a look at a few configuration options such as allowed_hosts and denied_hosts. You can edit these settings in the /etc/apt-cacher/apt-cacher.conf

allowed_hosts= (to allow all local machines)


You also need to configure Apt-Cacher to “go live” so you’ll need to change one more option in another file. Simply change the AUTOSTART within /etc/default/apt-cacher from 0 to 1.

sudo vim /etc/default/apt-cacher




And one last option to run on the server machine is to import any existing .deb packages on that machine into the Apt-Cache database. Use the following command to import your current cache:

sudo /usr/share/apt-cacher/ /var/cache/apt/archives

After you’ve made any of these changes to the apt-cacher.conf file you’ll need to restart Apt-Cacher by using:

sudo /etc/init.d/apt-cacher restart

The next thing to do is simply point your other local machines to this central machine instead of the central repositories. You’ll want to first backup your original sources.list using the command:

sudo cp /etc/apt/sources.list /etc/apt/sources.list-backup

And then simply edit your the file to look something more like:

deb http://[LOCAL.IP]:3142/ edgy main restricted
deb http://[LOCAL.IP]:3142/ edgy universe multiverse
deb http://[LOCAL.IP]:3142/ edgy-updates main restricted
deb http://[LOCAL.IP]:3142/ edgy-updates universe multiverse
deb http://[LOCAL.IP]:3142/ edgy-security main restricted
deb http://[LOCAL.IP]:3142/ edgy-security universe multiverse
You’ll notice that I’ve simply prefixed with the local network address of the machine running Apt-Cacher and specified the default port. This is a broken down version of a sources.list for the sake of space. From there on everything should run the same as normal.

Now you can give things a spin by checking for updates as normal.

sudo aptitude update && sudo aptitude upgrade

Everything should appear as normal. Remember you can also continue to use this to install individual packages on each machine. Not all the machines need to carry the same either. Whatever is requested from any machine will be checked on the Apt-Cacher server and retrieved if it isn’t yet available.

For more information on using Apt-Cacher you might be interested in these pages:

How to setup a repository cache with Apt-Cacher

Nick Andrew’s Apt-Cacher Page

Debian Universe Apt-Cacher Information

14 thoughts on “Save Bandwidth With Multiple Machines with Apt-Cacher : Ubuntu (6.10)

  1. emonkey

    There’s something similar called apt-proxy. I’m using apt-proxy since 3 years and it’s indispensable for me and my network with 5 K/Ubuntu computers.

    Where are the differences between the programs?

  2. Pingback: Blog de Sergi » Blog Archive » Caché local de repositoris Apt

  3. Phil

    For a one off job, I would normally just use sftp to the up to date computer, and grab the contents of /var/cache/apt/archives. You get a lot of old debs too of course, but it’s unlikely to take long over a network, and doesn’t take any work at all to set up…

  4. Pingback: kbglob - tecnologia para geeks, no para tu mamá » APT para redes corporativas

  5. Ubuntu Tutorials

    Bram – it would be nice if that would work by default. While it is nice once apt-cacher is setup actually setting things up on an entire network can take some time!

  6. Abbas

    Bram is right, apt-service-discovery should be implemented 🙂 by default.

  7. Scott

    I’d love to know how fast your internet connection is. DSL here is several meabytes per second.

    Your family’s telco must have pushed the DSL limit when they allowed them to have DSL there.

  8. EWB

    Rather than edit your sources.list, you can add
    Acquire::http::Proxy “http://apt-cache-machine:3142”;

    to your apt.conf. I think Synaptic has a dialog for this. If the apt-cacher machine is down, its easy to switch back to direct access.

  9. Pingback: Docunext Tech Stuff Archive » apt-cacher

  10. DNza

    Ubuntu Feisty Fawn install update from repository already downloaded:
    Easier way – I’m a noob and tried all sorts of things. Could be wrong but without a whole bunch of tweaking this doesn’t seem to work with Feisty, so I tried a more straight forward way – simply copy the package files into /var/cache/apt/archives/ !
    I Installed Feisty and fiddled so much I broke it & fixed it several times. Then I installed it again, same disk, new partition, clean install. But I didn’t want to download the updates again (“broad”band in S.A. is a p of beyond belief!), so I simply copied all the packages from the /var/cache/apt/archives/ on the first install to /var/cache/apt/archives/ on the second.
    NB: I had to do so as root or the copy/paste wasn’t possible.
    (To log in as root, System>Administration>Users and Groups; select root, click Properties, type & confirm a password, presto! Log out, log in as root, do your magic!) Good luck!

  11. Foo

    18 hours download on DSL? Were you downloading the entire internet?

  12. Pingback: Saving Bandwidth With Apt-Cacher : Revisited : Ubuntu Tutorials : Dapper - Edgy - Feisty - Gutsy

  13. Kelum

    Is there a way to update a computer by coping update files from /var/cache/apt/archives with out connecting to either a local area network?

Comments are closed.