Using apt-cacher-ng With LMDE

adolson
  13 years ago
  5

Introduction: Why Cache Packages?

Say you have multiple PCs on your home network that all run Linux Mint Debian Edition, and you want to keep them all up-to-date. Caching the packages is probably a good idea, because this way, you save on your bandwidth, and your PCs update much faster. I have three PCs, so the speed increase for updating is quite significant with this method - I can pull packages over my gigabit LAN far faster than I can grab them from Debian or Mint's servers. And the good news? It's really not difficult at all.

First thing to do is choose which system will be your cacher. It should be the PC that is on the most, since your other PC(s) will need to connect to it to update. I use a headless system in my basement to serve files such as pictures, music, and movies to my PlayStation 3 and other PCs, so this will also serve my .deb packages. We'll call this the server from now on, and the other PC(s) will be clients and configured the exact same. I am using a freshly-updated install of LMDE as of April 8, 2011 for this tutorial.

Caching Server Setup

Now, on the server, open up Software Manager and search for apt-cacher-ng and install it. Alternately, you can use the command line:

sudo apt-get install apt-cacher-ng

After it is installed, you need to configure the server to use itself as a proxy, so it will use the cache for any packages it wants to install. To do this, you need to edit or create a config file using your favorite text editor. For this tutorial, I'll assume you want to use gedit, so hit Alt+F2 to open up the Run Application dialog and then run this command:

gksudo gedit /etc/apt/apt.conf

By default this file doesn't exist, but if there is something in it, just start a new line and paste this line:

Acquire::http { Proxy "http://localhost:3142"; };

Now save the file and close gedit. Your server is now ready to go! To configure your clients, you will need to know your server's IP address, and it should probably be set up as static. This is beyond the scope of this tutorial, so if you aren't sure how to do that, you should learn that first. To get your server's IP address, right-click on the NetworkManager applet in your system tray, and go to Connection Information. You should see your IP address very clearly labeled here. For this tutorial, we'll assume that it says 192.168.0.13 is your IP.

Client Setup

Now, on each of your client PCs, you need to point it to your server's IP address in the same manner that you just did for the server itself. Once again, you need to edit or create a config file using your favorite text editor. To use gedit, so hit Alt+F2 to open up the Run Application dialog and then run this command:

gksudo gedit /etc/apt/apt.conf

Now, on a new line in this config file, paste this line:

Acquire::http { Proxy "http://192.168.0.13:3142"; };

Now save the file and close gedit. If you use Synaptic, you'll also need to configure it to use your server as a proxy. To do this, simply open Package Manager from the Mint menu, and then go to Settings > Preferences. Now, select the Network tab and choose the Manual proxy configuration radio button. For HTTP proxy, enter your server IP, 192.168.0.13 and port 3142. Now click OK and you're all set!

In Conclusion

From here on, the first time you install a package on any of your PCs set up this way, it will be fetched from the source and stored on your server. Subsequent installations will be much faster, as the other PCs will pull the cached version.

There is more to apt-cacher-ng than what this tutorial covers, but this is the bare minimum you need to do to get it up and running. It's quite easy, as you can see!