How to setup apt caching proxy

I am currently using cellular connection most of the time. Thus, it is obvious that I prefer to reduce the amount of data transferred over the network. Significant portion of it is reduced by the apt caching proxy apt-cacher-ng as I use Debian Linux distribution and VirtualBox on daily basis.

Install application

To install apt caching proxy execute the following command.

$ sudo apt-get install apt-cacher-ng

apt-cacher-ng service will start automatically and listen on the 3142 port.

Please note that maintenance page is not protected by default.

Protect maintenance page

To protect maintenance page edit /etc/apt-cacher-ng/security.conf configuration file to set username and password.

$ sudo vi /etc/apt-cacher-ng/security.conf 
# This file contains confidential data and should be protected with file
# permissions from being read by untrusted users.
# NOTE: permissions are fixated with dpkg-statoverride on Debian systems.
# Read its manual page for details.

# Basic authentication with username and password, required to
# visit pages with administrative functionality. Format: username:password

AdminAuth: administrator:secretpassword

Access maintenance page

Open http://localhost:3142 URL and navigate to the Statistics report and configuration page or jump directly to the http://localhost:3142/acng-report.html web page.

Adjust application settings

Edit /etc/apt-cacher-ng/acng.conf cofiguration file to define addresses/hostnames and port to listen on.

$ sudo vi /etc/apt-cacher-ng/acng.conf
BindAddress: localhost

Configure APT

Instruct APT to use recently configured proxy.

$ sudo vi /etc/apt/apt.conf.d/00proxy
Acquire::http::Proxy "";

Import packages

To import already downloaded packages you need to perform the following steps.

Create /var/cache/apt-cacher-ng/_import/ directory.

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

Copy or move downloaded packages to the directory created in the previous step.

$ sudo cp /var/cache/apt/archives/*.deb /var/cache/apt-cacher-ng/_import/
Notice that packages are deleted after successful import.

Fix permissions.

$ sudo chown -R apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng/_import

Initiate import on the maintenance page.

If packages are not imported then run apt-get update action on the machine using selected repository and apt cache proxy.

Customize HTML templates

To customize default web page edit /usr/lib/apt-cacher-ng/userinfo.html file.

$ sudo vi /usr/lib/apt-cacher-ng/userinfo.html

To customize maintenance web page /usr/lib/apt-cacher-ng/report.html file.

$ sudo vi /usr/lib/apt-cacher-ng/report.html


Visit Apt-Cacher NG website to read user manual, mailing list or bug tracker.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland