Apt-Cacher-NG – HTTP download proxy for software packages

Sponsored Link
Apt-Cacher-ng is a software package that keeps a cache, on the disk, of Debian/Ubuntu Packages and Release files.When an apt-get like client issues a request for a file, Apt-Cacher intercepts it and if the file is already cached it serves it to the client immediately, otherwise it fetches the file from the Internet, saves it on the cache, and then serves it to the client. This means that several Debian machines can be upgraded but each package need to be downloaded only once.

Apt-Cacher-NG does not require neither an interpreter, nor a web server and not even a huge runtime library. It does never fork after server startup, it does not create flag files, flock() files or similar fun. Instead, it uses native system functions (mmap, sendfile) to operate with few overhead.

Apt-cacher-ng caches the repo's from the different versions of ubuntu quite nicely. It even nicely supports the different installs of intrepid in my home with different personal package archives (PPA, you know as in ppa.launchpad.net/*).

Install Apt-Cacher-NG in Ubuntu Intrepid

First you need to download the latest version of Apt-Cacher-NG from here or using the following command

wget http://ftp.debian.org/debian/pool/main/a/apt-cacher-ng/apt-cacher-ng_0.3.3-1_i386.deb

Install .deb package using the following command

sudo dpkg -i apt-cacher-ng_0.3.3-1_i386.deb

or you can use the following command to install

sudo apt-get install apt-cacher-ng

Now you need to Add a proxy entry to the apt system

Configure the apt system (apt-get, aptitude, etc.) to use apt-cacher-ng

$ echo ‘Acquire::http { Proxy "http://localhost:3142″; };' | sudo tee /etc/apt/apt.conf.d/01proxy

Run the following command if you need to disable it

sudo rm /etc/apt/apt.conf.d/01proxy

Add a proxy entry to the Synaptic system for this go to: Settings->Preferences->Network->Manual Proxy Configuration and enter

HTTP Proxy: localhost 3142

FTP Proxy: localhost 3142

Click OK

Click Reload

Dashboard & manual

For apt-cacher-ng dashboard use the following URL

http://localhost:3142/acng-report.html

For apt-cacher-ng manual: (right click &) open with your browser

file:///usr/share/doc/apt-cacher-ng/html/index.html

Import .deb files from the local apt cache

apt-cacher-ng use the .deb files that are already in /var/cache/apt/archives/

sudo mkdir -p /var/cache/apt-cacher-ng/_import

sudo chown apt-cacher-ng /var/cache/apt-cacher-ng/_import

Now open browser using the following URL

http://localhost:3142/acng-report.html

and click "Start Import"

Configure Client Machines

If you want to use apt-cache-ng in ubuntu or debian clients use the following command to use this proxy

$ echo ‘Acquire::http { Proxy "http://serverip:3142″; };' | sudo tee /etc/apt/apt.conf.d/01proxy

Sponsored Link

Incoming search terms:

Related posts

20 thoughts on “Apt-Cacher-NG – HTTP download proxy for software packages

  1. So this is kinda like WSUS?
    I was thinking about creating a local Ubuntu Repository on my home network.
    I don’t think it would be that hard…
    -setup a server with plenty of disk space ~ 500GB,
    -setup chron job to sync over the internet every 6, 12 or 24 hours, or a certain time
    -point all local machines to the local repository. updates would install super quick over LAN speeds!

    [Reply]

  2. This is more transparent then WSUS. Everything is the same as before but instead of downloading the file from the repository for each computer on your network, you just download it once and all the other computers get it from the Apt-cacher-ng. I used it before and ended up getting mismatched Keys… but it was an older version of the software.

    [Reply]

  3. Paul – apt-mirror will already manage this for you if you have the bandwidth.

    Have used this in place of apt-proxy as it seems much more robust under load – brilliant if you have many machines doing the same updates etc.

    [Reply]

  4. I don’t understand this tutorial. Do I have to install apt-cache-ng on client machine as well like on server machine or on client I just have to set proxy in /etc/apt/apt.conf.d/01proxy?

    [Reply]

  5. No need to install on the client, just the server. The proxy on the server will deal with picking the place to retrieve the file from (cached local or from the external repository).

    [Reply]

  6. I use apt-zeroconf for my home network. With apt-zeroconf I don’t need any repositories set up on _one_ machine. Every machine on the network shares packages between them.

    [Reply]

  7. It is not working:

    echo ‘Acquire::http { Proxy “http://localhost:3142?; };’ | sudo tee /etc/apt/apt.conf.d/01proxy
    -bash: syntax error near unexpected token `}’

    And wenn I create the /etc/apt/apt.conf.d/01proxy file manually and insert

    Acquire::http { Proxy “http://localhost:3142?; };

    apt claims that there is unsuspected trash at line end.

    Can you maybe post your /etc/apt/apt.conf.d/01proxy file?

    Thank you.

    [Reply]

  8. I found the solution – I copied & pasted from your article, but your code contains ? and ’ instead of ” and ‘ – it can not work with this characters. I think WordPress converted the characters when you copied the code into the article.

    [Reply]

  9. This is amazing… I’m immediately going to toss out my transparent proxy that “does the exact same thing” so that I can install a product that requires client side configuration. Then I’m going to put square wheels on my car and rip out my gas furnace and replace it with a coal stove.

    F

    [Reply]

  10. Frank, how is your comments helpful? Seems to me his solution is easier and simpler that setting a transparent proxy. How about you write something up on setting up your transparent proxy and we can compare it to his solution for ease of setup.

    [Reply]

  11. I’ve been using this for a few months very happily with intrepid and one client – and now a Jaunty virtualbox client. Works a treat.
    Soon it will be time to upgrade all of them to Jaunty. Can anyone tell me if I’ll have to muck around with a stand-in server* while my current server upgrades over apt-cacher, or can I just keep the Jaunty vbox up to date to get the new debs into the cache, then upgrade the server? (the server already points to itself via the proxy on localhost:3142). Hope that makes sense!

    Any tips would be greatly appreciated….

    *by this I mean setting up a temporary apt-cacher box, onto which i could copy all the debs pulled down by the Jaunty virtualbox so far. Basically, I’m hoping server could use its own cache during the upgrade…

    [Reply]

  12. Thanks for this – maybe should mention the way to install this on a debian or ubuntu machine is
    apt-get install apt-cache-ng
    Then configure it to whatever port you want and firewall any public IP.
    I think something got garbled up with your one liner to add the new setting to apt – here’s mine:

    cat > /etc/apt/apt.conf.d/01proxy <<EOF
    Acquire::http { Proxy "http://192.168.0.3:9999&quot; }

    EOF

    [Reply]

  13. It’s the smart quotes. ? is not the same as “. It works fine if you type it out, but copying and pasting fails.

    [Reply]

  14. Thanks. My installation of apt-cacher was acting slow and was frequently dropping connection. But apt-cacher-ng works as advertised!!

    [Reply]

  15. I’m trying to set this up on Ubuntu 9.10 server with ubuntu-desktop installed on top of it.

    Are there any changes that need to be made to this?

    I see they are up to version 0.4.6-1 which is newer than what is in the Ubuntu repos (0.4-1).

    What, if any, improvements are there in the newer versions?

    [Reply]

  16. > I’m trying to set this up on Ubuntu 9.10 server with ubuntu-desktop installed on top of it.
    > Are there any changes that need to be made to this?

    I didn’t need to make any changes. Make sure you read the comments about smart quotes though.

    [Reply]

Leave a comment

Your email address will not be published. Required fields are marked *