Apt-Cacher NG is a caching proxy server for Debian-based Linux distributions including Ubuntu, Debian, Linux Mint, etc. It creates a local cache of the Debian mirrors and other Linux distributions. When you use the apt command to install any package, the package is pulled from the official repositories, and the APT cache server caches that package in the system. When you install the same package again, it will download that package from the local caching server. This will save you a lot of time and internet bandwidth.

In this post, we will explain how to set up an APT-Caching server using Apt-Cacher NG on Ubuntu. This procedure is compatible with Ubuntu 20.04 and Ubuntu 22.04.

Step 1 – Install Apt-Cacher-NG

By default, the Apt-Cacher-NG package is included in the Ubuntu default repository. You can install it using the following command:

apt-get update -y
apt-get install apt-cacher-ng -y

Once the Apt-Cacher-NG package is installed, start the Apt-Cacher-NG service and enable it to start at system reboot:

systemctl start apt-cacher-ng
systemctl enable apt-cacher-ng

You can check the status of Apt-Cacher-NG with the following command:

systemctl status apt-cacher-ng

Sample output:

● apt-cacher-ng.service - Apt-Cacher NG software download proxy
     Loaded: loaded (/lib/systemd/system/apt-cacher-ng.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-08-15 07:13:14 UTC; 20s ago
   Main PID: 3748 (apt-cacher-ng)
      Tasks: 1 (limit: 2353)
     Memory: 2.0M
     CGroup: /system.slice/apt-cacher-ng.service
             └─3748 /usr/sbin/apt-cacher-ng -c /etc/apt-cacher-ng ForeGround=1

Aug 15 07:13:13 ubuntu2004 systemd[1]: Starting Apt-Cacher NG software download proxy...
Aug 15 07:13:14 ubuntu2004 systemd[1]: Started Apt-Cacher NG software download proxy.

By default, Apt-Cacher-NG listens on port 3142. You can check it with the following command:

ss -altnp | grep apt

Sample output:

LISTEN    0         250         *        users:(("apt-cacher-ng",pid=3748,fd=10))                                       
LISTEN    0         250                   [::]:3142                [::]:*        users:(("apt-cacher-ng",pid=3748,fd=11))                                       

Step 2 – Configure Apt-Cacher-NG

By default, Apt-Cacher NG does not serve HTTPS repositories, so you will need to enable it. To do so edit the Apt-Cacher-NG default configuration file:

nano /etc/apt-cacher-ng/acng.conf

Uncomment the following line:

PassThroughPattern: .*

Save and close the file, then restart the Apt-Cacher-NG service to apply the changes:

systemctl restart apt-cacher-ng

Step 3 – Configure Client System to use Apt-Cacher NG

By default, all Ubuntu system uses Ubuntu repository to download and install packages, so you will need to configure your client system to use Apt-Cacher NG for package installation.

To do so, create a new proxy configuration file:

nano /etc/apt/apt.conf.d/00aptproxy

Add the following line:

Acquire::http::Proxy "http://your-server-ip:3142";

Save and close the file when you are finished.

Step 4 – Verify APT-Cacher NG

Now, let’s try to install the Apache package on the Client system using the following command:

apt-get install apache2 -y

The above command will find, download, and install an Apache package from the Apt-Cache NG server.

You can check it using the following command on the server system:

tail -f /var/log/apt-cacher-ng/apt-cacher.log

Sample output:


Apt-Cache NG also provides a web-based interface to display all reports. You can access it using the URL
http://your-server-ip:3142/acng-report.html. You should see the following screen:
APT-Cache NG Dashboard Page

Step 5 – Control Apt-Cacher NG Usage

You can also set up access control for Apt-Cache NG so that only authenticated hosts can download the package from the Apt-Cacher NG server.

You can use the /etc/hosts.allow and /etc/hosts.deny for controling access.

For example, to allow and to use Apt-Cacher NG server, edit the /etc/hosts.allow file:

nano /etc/hosts.allow

Add the following line:

apt-cacher-ng :

Save and close the file when you are finished.

If you want to block the host to use Apt-Cacher NG server, edit the /etc/hosts.deny file:

nano /etc/hosts.deny

Add the following line:

apt-cacher-ng :

Save and close the file when you are finished.


In the above guide, we explained how to install and use Apt-Cache NG server on Ubuntu 20.04 server. You can now set up Apt-Cache NG in your local network to save a lot of internet bandwidth – try it on VPS hosting from Atlantic.Net!