In environments managing multiple Ubuntu servers, virtual machines, homelab nodes, or continuous integration runners, executing apt update and apt upgrade across every machine downloads identical .deb package archives repeatedly. This redundant traffic saturates external internet connections and introduces unnecessary latency into system deployment workflows.
While establishing a full local Debian/Ubuntu repository mirror requires hundreds of gigabytes of disk space and regular synchronization jobs, apt-cacher-ng provides a specialized, lightweight alternative. It operates as an on-demand caching HTTP proxy: it downloads packages only when requested by client machines, caches the immutable archive files locally, and serves subsequent requests across the local network at full gigabit speeds.
Installing apt-cacher-ng on the Cache Server
Designate an Ubuntu Server instance with adequate storage to host the cache. Update your package lists and install apt-cacher-ng:
sudo apt update
sudo apt install -y apt-cacher-ng
By default, the daemon listens on TCP port 3142. Confirm that the service is running and active:
sudo systemctl status apt-cacher-ng
Configuring Server Storage and Network Directives
The primary configuration file resides at /etc/apt-cacher-ng/acng.conf. Open it in a text editor to review key settings:
sudo nano /etc/apt-cacher-ng/acng.conf
Key directives to verify or customize include:
CacheDir: /var/cache/apt-cacher-ng: The directory where cached package archives are stored. Ensure the underlying mount has adequate disk space.LogDir: /var/log/apt-cacher-ng: Destination directory for connection and error logs.Port: 3142: Default listening port.BindAddress: 0.0.0.0: Set to listen on all network interfaces so client machines can access the proxy.
If you modify any settings, restart the service to apply changes:
sudo systemctl restart apt-cacher-ng
Configuring Ubuntu Client Machines to Use the Cache Proxy
To direct client Ubuntu systems to route package downloads through your cache server, configure an APT proxy configuration file. On each client machine, create a new configuration snippet:
sudo nano /etc/apt/apt.conf.d/00aptproxy
Add the following directive, replacing 192.168.1.50 with the local IP address of your apt-cacher-ng server:
Acquire::http::Proxy "http://192.168.1.50:3142";
If your package sources include third-party HTTPS repositories, you can instruct APT to connect directly or pass through the proxy:
Acquire::https::Proxy "DIRECT";
Testing Cache Performance and Acceleration
Once configured, test package retrieval on your client machine:
sudo apt update && sudo apt dist-upgrade
During the first run on client 1, apt-cacher-ng downloads the packages from official mirrors and stores them in its local cache. When you run the update on client 2, APT downloads the packages directly from your local cache server at full local network bandwidth (often 100MB/s or higher), bypassing internet bottlenecks entirely.
Accessing the Web Statistics Dashboard and Cache Maintenance
apt-cacher-ng includes a built-in web-based management and reporting interface. Open a browser and navigate to:
http://<your-server-ip>:3142/acng-report.html
The dashboard provides comprehensive metrics:
- Cache Hit Rate: Percentage of data served from local disk versus upstream downloads.
- Bandwidth Savings: Total megabytes transferred to clients versus total megabytes fetched externally.
- Cache Expiration and Scrubbing: Use the “Start Scan and Expiration” button to scan for superseded package versions and prune obsolete archives, keeping disk utilization under control.