If you patch more than a few Ubuntu servers on the same network, each one downloads the same .deb files from the internet. APT-Cacher NG fixes that. You install it on one Ubuntu Server host and point every client’s APT at port 3142. Only the first machine to request a package pulls it from the internet. Every other client gets it from local disk.
This guide covers the full apt-cacher-ng Ubuntu setup: install, client config, and the HTTPS limitation that trips up a lot of admins. It also covers cache cleanup with acngtool, locking the service to your LAN, and when a full local mirror is the better choice.
Quick Reference
| Question | Short answer |
|---|---|
| What port does apt-cacher-ng use? | TCP 3142 by default (Port in /etc/apt-cacher-ng/acng.conf) |
| How do clients find the cache? | A line like Acquire::http::Proxy "http://192.168.1.10:3142"; in a file under /etc/apt/apt.conf.d/ |
| Are HTTPS repos cached? | No. Encrypted traffic can only be tunneled, and tunneled traffic isn’t cached. Switch the repo to plain HTTP or allow pass-through |
| Where is the cache stored? | /var/cache/apt-cacher-ng (CacheDir) |
| How do I clean it up? | Use acngtool for routine expiration. Check your installed manpage before using the older daemon -e flag by hand |
| How do I restrict access? | Set BindAddress to a LAN interface and allow 3142 only from your subnet in ufw |
| When should I use a full mirror instead? | When you need offline installs, guaranteed availability, or every client pulls very different package sets |
What Is APT-Cacher NG?
APT-Cacher NG is a caching proxy built for APT, the package manager on Ubuntu and other Debian-based distributions. It sits between your clients and the real repositories. When a client asks for a package, apt-cacher-ng fetches it once and saves it to disk. Every later client that asks for the same file gets the saved copy.
It stores only the files clients actually request. That keeps disk usage low, but the first request for any file is always a cache miss.
There’s no graphical admin app or desktop UI. You configure everything through plain-text files in /etc/apt-cacher-ng and manage the daemon with systemd. The daemon also serves a simple built-in report page on its listening port. That page is the closest thing it has to a dashboard. See the apt-cacher-ng(8) manpage for Ubuntu 24.04 (noble) for the upstream reference.
Prerequisites
- An Ubuntu Server host to run the cache. The apt-cacher-ng manpages are published for current releases including 24.04 LTS (noble) and 26.04 LTS (resolute)
- A static IP or DHCP reservation on that host. Clients hard-code this address
- One or more Ubuntu or Debian-based clients on the same LAN
sudoaccess on the cache host and every client- Enough free disk for the cache. Size depends on how many releases and architectures you serve. A dedicated SSD or a volume on a NAS drive works well if you expect it to grow
- SSH access to all machines
| Requirement | Details |
|---|---|
| Cache host OS | Ubuntu Server 24.04 LTS or 26.04 LTS |
| Package source | apt-cacher-ng from the standard Ubuntu repositories |
| Network | Clients must reach the cache host on TCP 3142 |
| Hardware | Any always-on box: a VM, a mini PC, or a Raspberry Pi running Ubuntu Server. Put it on a UPS if your patch runs depend on it |
| Example addresses used here | Cache host 192.168.1.10, LAN 192.168.1.0/24 |
Note on versions: This guide doesn’t quote a specific apt-cacher-ng package version. Check what your release ships with
apt-cache policy apt-cacher-ngbefore you start.
Step-by-Step Guide: Installing APT-Cacher NG on Ubuntu
Step 1: Check the Available Package Version
On the machine that will host the cache, refresh the package index. Then see which version your release offers.
sudo apt update
apt-cache policy apt-cacher-ng
You should see output shaped like this, where VERSION is the package version for your release and CODENAME is your release codename.
apt-cacher-ng:
Installed: (none)
Candidate: VERSION
Version table:
VERSION 500
500 http://archive.ubuntu.com/ubuntu CODENAME/universe amd64 Packages
Installed: (none) confirms it isn’t on the system yet. Write down the candidate version. It helps when you check release-specific docs later.
Step 2: Install apt-cacher-ng
sudo apt install apt-cacher-ng
During install, debconf may ask whether to allow HTTP tunnels through the proxy. That question ties into the HTTPS behavior in Step 8. If you aren’t sure, answer No for now. You can change it later in the config files.
On most current Ubuntu releases, systemd automatically enables and starts a service right after installation, and apt-cacher-ng typically follows that pattern. Confirm this on your system with the status check below rather than assuming it from documentation alone.
Step 3: Confirm the Service Is Running on Port 3142
Check the systemd unit:
systemctl status apt-cacher-ng
The lines that matter look like this:
● apt-cacher-ng.service - Apt-Cacher NG software download proxy
Loaded: loaded (/usr/lib/systemd/system/apt-cacher-ng.service; enabled; preset: enabled)
Active: active (running) since ...
Look for active (running) and enabled. Exact unit file paths and description text can vary a bit by release.
Next, confirm the daemon is listening on 3142:
sudo ss -ltnp | grep 3142
# -l listening sockets, -t TCP only, -n numeric ports, -p show owning process
LISTEN 0 250 0.0.0.0:3142 0.0.0.0:* users:(("apt-cacher-ng",pid=...,fd=...))
LISTEN 0 250 [::]:3142 [::]:* users:(("apt-cacher-ng",pid=...,fd=...))
0.0.0.0:3142 means it listens on all IPv4 interfaces. The upstream apt-cacher-ng server configuration manual documents listening on all IPv4 and IPv6 interfaces as the default when BindAddress is unset. You’ll narrow this in Step 9.
Step 4: Review the Configuration Directory
ls /etc/apt-cacher-ng
You’ll find several files. The three that matter most:
acng.conf: the main config withCacheDir,LogDir,Port,BindAddress, and moresecurity.conf: settings you don’t want world-readable, such as admin credentials for the report page’s maintenance functionszz_debconf.conf: values written by the package installer, such as your tunnel answer from Step 2
Current packaging reads every .conf file in this directory. Files that load later can override earlier settings. That’s why the debconf file is named zz_, so it normally sorts and loads after the other files (a local file whose name sorts later could still override it). Keep this in mind: if you edit a setting in acng.conf and nothing changes, check whether zz_debconf.conf sets the same directive.
Read the active, non-comment lines of the main config:
grep -Ev '^\s*(#|$)' /etc/apt-cacher-ng/acng.conf
# -E extended regex, -v invert match: hides comments and blank lines
The acng.conf file has extensive comments. It’s the most reliable reference for directive syntax on your installed version. Read through it once.
Step 5: Set the Cache and Log Locations (Optional)
Defaults:
| Setting | Default | Purpose |
|---|---|---|
CacheDir | /var/cache/apt-cacher-ng | Where cached packages live |
LogDir | /var/log/apt-cacher-ng | Where logs are written |
Port | 3142 | TCP port clients connect to |
If your root filesystem is small, move the cache to a larger disk. Stop the service first so nothing writes mid-copy:
sudo systemctl stop apt-cacher-ng
sudo mkdir -p /srv/apt-cacher-ng
sudo rsync -a /var/cache/apt-cacher-ng/ /srv/apt-cacher-ng/
# -a preserves ownership and permissions, which the daemon needs
sudo chown -R apt-cacher-ng:apt-cacher-ng /srv/apt-cacher-ng
Then edit the config:
sudoedit /etc/apt-cacher-ng/acng.conf
# /etc/apt-cacher-ng/acng.conf
CacheDir: /srv/apt-cacher-ng
Start the service again:
sudo systemctl start apt-cacher-ng
Warning: The daemon runs as the
apt-cacher-nguser. If that user doesn’t own the newCacheDir, downloads will fail with permission errors. Verify withls -ld /srv/apt-cacher-ng.
Step 6: Point Your First Client at the Cache
On a client server, create a proxy file under /etc/apt/apt.conf.d/:
sudoedit /etc/apt/apt.conf.d/00aptproxy
Add one line, replacing the IP with your cache host’s address:
// /etc/apt/apt.conf.d/00aptproxy
Acquire::http::Proxy "http://192.168.1.10:3142";
About the filename. Guides use 00aptproxy, 01proxy, 02proxy, and others. APT doesn’t care about the exact name, and it reads every file in /etc/apt/apt.conf.d/, so any of these names works for the setting to take effect.
The low number is just a convention that makes the file sort near the top of a directory listing and easy to spot. What matters is placing the file in the right directory and following the directive’s syntax shown in the example, including ending the line with a semicolon as in the sample above.
Confirm APT actually reads the setting:
apt-config dump Acquire::http::Proxy
Acquire::http::Proxy "http://192.168.1.10:3142";
If this prints nothing, APT isn’t seeing your file. Check the path and the semicolon.
Step 7: Run the First Update and Verify Cache Hits
On the client:
sudo apt update
A successful apt update is only a first sign that the client is talking to the proxy. It doesn’t prove the request went through the cache (APT may still be using a different proxy setting or cached indexes), and it doesn’t prove anything was cached. To confirm, watch the server log while a client runs updates. On the cache host:
sudo tail -f /var/log/apt-cacher-ng/apt-cacher.log
# -f follows the file as new lines arrive; Ctrl+C to stop
The main access log in LogDir is usually named apt-cacher.log. If yours differs, run ls /var/log/apt-cacher-ng. You should see new entries for each file the client requests.
Now run sudo apt update on a second client set up the same way. Index files and packages the first client already fetched should now come from local disk. The first machine always pays the full download cost. That’s expected.
Step 8: Handle HTTPS Repositories
This is where most quick-start guides fall short.
Why HTTPS isn’t cached. APT-Cacher NG is documented as a proxy for HTTP repository access. With HTTPS, the TLS session runs end to end between the client and the real repository. The proxy only sees encrypted bytes. It can’t read the file name, and it can’t store a reusable copy. The best it can do is tunnel the connection through (the HTTP CONNECT method). Tunneled traffic passes through uncached.
For HTTPS sources, you have three options.
Option A: Use HTTP for repos that support it. On many Ubuntu installations, the main archive (archive.ubuntu.com) and security archive (security.ubuntu.com) are configured over http://, though the exact scheme can depend on your release and how your sources were set up. Check your own client configuration before assuming either way.
Ubuntu and APT have long maintained package integrity through cryptographic signatures rather than relying solely on the transport protocol, which is part of why plain HTTP has historically been workable for these archives. For the full technical details on how APT verifies packages, see Ubuntu’s own documentation rather than this guide. Check your client sources:
grep -rh '^URIs:\|^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/
# hides the error if sources.list doesn't exist on deb822-only systems
On Ubuntu 24.04 and later, the default sources use the deb822 format in /etc/apt/sources.list.d/ubuntu.sources. Any URIs: line starting with http:// will be cached. Third-party repos that only offer https:// won’t be.
Option B: Tunnel HTTPS without caching it. If you also set an HTTPS proxy on the client, APT sends HTTPS requests to apt-cacher-ng as CONNECT tunnels. Unless your configuration allows them (check PassThroughPattern in acng.conf and the install-time answer in zz_debconf.conf), apt-cacher-ng refuses those, and the update fails. You allow them with the PassThroughPattern directive in the server config. It takes a regular expression matched against the target host and port.
A common form allows tunnels only to specific hosts on port 443:
# /etc/apt-cacher-ng/acng.conf
# Allow CONNECT tunnels (uncached) to these HTTPS repository hosts only
PassThroughPattern: ^(download\.docker\.com|packages\.example\.com):443$
Verify before you rely on this: The exact expected format can differ between releases. Read the
PassThroughPatterncomments in your installedacng.conf. Also checkzz_debconf.conf, which may set it based on your install-time tunnel answer. Some guides recommendPassThroughPattern: .*. That allows tunnels to any host and turns your cache into an open HTTPS forward proxy for anyone who can reach it. Keep the pattern narrow.
Restart after editing:
sudo systemctl restart apt-cacher-ng
Option C: Don’t proxy HTTPS at all. Set only Acquire::http::Proxy on clients, as in Step 6, and leave Acquire::https::Proxy unset. APT then fetches HTTPS repos straight from the internet, and HTTP repos go through the cache. This is the simplest option. It’s also what the Step 6 client config already does.
For most homelabs, Option A plus Option C covers it. The heavy traffic from Ubuntu’s own archive gets cached, and third-party HTTPS repos keep working directly.
Step 9: Restrict Access to Your Trusted Network
An apt-cacher-ng instance reachable from the internet is a free download proxy for strangers. If you’ve opened pass-through patterns, it’s worse. Lock it down at two layers.
Layer 1: BindAddress. Tell the daemon to listen only on your LAN-facing address.
Some admins also add localhost so the cache host can route its own updates through its local proxy. Treat that as an advanced, optional step rather than a default: it only works cleanly if localhost is in BindAddress and you’ve confirmed the cache host doesn’t depend on that same proxy to recover when the service is down or misconfigured. If you’re not sure, leave the cache host’s own APT pointed directly at the upstream repositories and only list your LAN address here.
# /etc/apt-cacher-ng/acng.conf
BindAddress: 192.168.1.10 localhost
BindAddress accepts multiple addresses, resolved at startup. Restart and recheck:
sudo systemctl restart apt-cacher-ng
sudo ss -ltnp | grep 3142
You should now see 192.168.1.10:3142 and loopback entries instead of 0.0.0.0:3142.
Layer 2: ufw. Allow 3142 only from your subnet:
Warning: If
ufwisn’t enabled yet, allow SSH before you runufw enable, or you’ll lock yourself out of a remote server.
sudo ufw allow OpenSSH
sudo ufw allow from 192.168.1.0/24 to any port 3142 proto tcp
# Only hosts in 192.168.1.0/24 can reach the cache on TCP 3142
sudo ufw enable
sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] OpenSSH ALLOW IN Anywhere
[ 2] 3142/tcp ALLOW IN 192.168.1.0/24
If you serve several VLANs, add one allow from rule per subnet. Never port-forward 3142 on your router.
Step 10: Check the Built-In Report Page
From a browser on your LAN, open the cache host on port 3142:
http://192.168.1.10:3142/
The root page shows basic usage info and a link to the report page. The ReportPage directive in acng.conf sets the report page path. On many installs it’s acng-report.html. Confirm the value on your system:
grep -i '^ReportPage' /etc/apt-cacher-ng/acng.conf
The report page shows transfer stats, including how much data came from cache versus upstream. It’s the quickest way to confirm the cache earns its keep. It also exposes maintenance actions. Those can require the admin credentials set in security.conf.
Step 11: Roll Out to the Rest of Your Servers
Once one client works, push the same file to the rest. A simple SSH loop works for a handful of hosts:
for host in web01 web02 db01; do
ssh "$host" 'echo "Acquire::http::Proxy \"http://192.168.1.10:3142\";" | sudo tee /etc/apt/apt.conf.d/00aptproxy' \
|| echo "FAILED: $host"
done
# tee writes the file with sudo and overwrites any existing 00aptproxy on the host;
# the escaped quotes keep APT's required quoting intact
For larger fleets, drop the file with your config management tool (Ansible, cloud-init, and similar). Bake it into VM templates so new machines use the cache from first boot.
Configuration: Cache Maintenance and Key Settings
Expiring Old Packages with acngtool
The cache grows as new package versions arrive. Old versions stay on disk until something removes them. That something should be acngtool, the separate maintenance utility.
One gotcha. Older guides tell you to run the daemon with the -e flag to trigger expiration, and running it by hand as root can leave cache files owned by the wrong user. When that happens, the service can no longer update or delete them normally.
On Debian and Ubuntu, the package ships acngtool together with a daily cron job, /etc/cron.daily/apt-cacher-ng, that calls it. By default that job runs the expiration operation with default parameters and stays quiet unless something fails (errors go to cron mail). The apt-cacher-ng maintenance documentation describes this setup. Check the apt-cacher-ng(8) manpage for your installed version too.
Confirm the job exists on your cache host:
ls -l /etc/cron.daily/apt-cacher-ng
cat /etc/cron.daily/apt-cacher-ng
To run the same expiration by hand, for example after a big cleanup of old releases, run the packaged script rather than the daemon’s -e flag:
sudo /etc/cron.daily/apt-cacher-ng
The script asks the running daemon to do the expiration, so files stay owned by the service user. If the job is missing (a custom or minimal install), you can also trigger expiration from the report page in Step 10.
Warning: Don’t clear the cache with
sudo rm -rf /var/cache/apt-cacher-ng/*while the service is running. If you truly need a clean slate, stop the service first, then delete, then start it again. Every client’s next update will be a full cache miss.
Key Settings Reference
| Directive | File | Default | When to change it |
|---|---|---|---|
CacheDir | acng.conf | /var/cache/apt-cacher-ng | Root disk is small; move to a bigger volume |
LogDir | acng.conf | /var/log/apt-cacher-ng | Separate log storage |
Port | acng.conf | 3142 | Port conflict; update every client too |
BindAddress | acng.conf | Unset (all interfaces) | Always, on multi-homed or internet-facing hosts |
PassThroughPattern | acng.conf / zz_debconf.conf | Check your installed file | Only to tunnel specific HTTPS repos (uncached) |
ReportPage | acng.conf | Check your installed file | Rename or locate the stats page |
After any change, apply and confirm:
sudo systemctl restart apt-cacher-ng
systemctl is-active apt-cacher-ng
active
Caching Proxy vs. Full Local Mirror
A full mirror (built with apt-mirror or an rsync of the archive) and apt-cacher-ng solve overlapping problems. They go about it in very different ways.
| apt-cacher-ng | Full local mirror | |
|---|---|---|
| What it stores | Only files clients have requested | The whole archive, or a chosen subset |
| Disk usage | Small, grows with real usage | Large, plus ongoing sync |
| First request | Always a cache miss | Already local |
| Offline installs | Only for previously fetched packages | Yes, for everything mirrored |
| Setup effort | Install, one client line | Initial sync, scheduled syncs, web server |
| HTTPS repos | Not cached; tunnel or go direct | Mirrored over whatever protocol the sync tool supports |
Pick apt-cacher-ng when your machines run similar package sets and you want fewer repeat downloads with little disk and upkeep. That describes most homelabs, small offices, and fleets of identical VMs.
Pick a full mirror when you need guaranteed local availability. Think air-gapped networks, installs that must work during an internet outage, or many machines that each pull different packages, so the cache rarely hits. Be ready for the disk bill, and keep sync jobs healthy.
Both run fine on modest hardware. On a busy LAN, wired networking (Cat6 Ethernet cable and a 2.5GbE switch) matters more than CPU. A cache hit is limited by how fast the server can push bytes to clients.
Tips and Troubleshooting
Clients Don’t Seem to Use the Cache
Why it happens: The proxy file is missing, isn’t under /etc/apt/apt.conf.d/, has a syntax error, or points to the wrong IP or port.
Fix:
- Run
apt-config dump Acquire::http::Proxyon the client. Empty output means APT isn’t reading your file. - Check the file:
cat /etc/apt/apt.conf.d/00aptproxy. Make sure the line has quotes and ends with;. - Run
sudo apt updateand watch/var/log/apt-cacher-ng/apt-cacher.logon the server for new entries.
“Connection Refused” When a Client Runs apt update
Why it happens: The service isn’t running, isn’t listening on 3142, or a firewall blocks the client.
Fix:
- On the server, run
systemctl status apt-cacher-ng. - Confirm the listener:
sudo ss -ltnp | grep 3142. - Check firewall rules:
sudo ufw status numbered. The client’s subnet must be allowed. - From the client, test reachability with a basic request:
curl -I http://192.168.1.10:3142/
# -I fetches headers only; any HTTP response means the port is reachable
This only shows the port answers HTTP. It doesn’t prove the client’s APT proxy setting is correct, so follow up with sudo apt update on the client while tailing the server log (Step 7).
Works on the Cache Host but Not from Other Machines
Why it happens: BindAddress is set to localhost or the wrong interface. The default listens on all interfaces, so a restrictive custom value is the usual cause.
Fix: Check grep -i BindAddress /etc/apt-cacher-ng/*.conf, add the LAN address, and restart. Grepping all .conf files catches overrides in later files.
apt update Fails on HTTPS Repositories
Why it happens: The client has Acquire::https::Proxy set, or an Acquire::Proxy catch-all. HTTPS requests then go to apt-cacher-ng as CONNECT tunnels, and the server refuses them.
Fix: Either remove the HTTPS proxy line from the client so HTTPS repos go direct (Option C in Step 8), or add a narrow PassThroughPattern on the server for those hosts (Option B). Neither makes HTTPS content cacheable.
Permission Errors During Cache Cleanup
Why it happens: Expiration ran through the legacy daemon -e flag, often as root. That leaves files the service user can’t modify.
Fix: Stop using -e. Restore ownership, then use acngtool going forward:
sudo systemctl stop apt-cacher-ng
sudo chown -R apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng
sudo systemctl start apt-cacher-ng
If you moved CacheDir, substitute your path.
First Update After Setup Isn’t Any Faster
Why it happens: Expected. The cache is empty, so the first client fetches everything from upstream.
Fix: None needed. The benefit shows up on the second and later clients that request the same files. Patch one canary server first, then the rest. The canary warms the cache for the fleet.
Cache Disk Fills Up
Why it happens: You’re serving multiple Ubuntu releases or architectures, and expiration isn’t running.
Fix: Check usage with sudo du -sh /var/cache/apt-cacher-ng. Confirm a maintenance job exists (see the acngtool section) and run expiration. Move CacheDir to a larger volume if needed (Step 5).
Quick Tips
- Stagger patch runs: Update one host first, then the fleet. Simultaneous first requests for the same file still each hit the upstream path less efficiently than a warm cache.
- Give the cache host its own direct path: Don’t route the cache host’s own updates through its
localhost:3142proxy unless you’ve tested that setup end to end. Self-proxying can create a dependency loop: if the apt-cacher-ng service is down, misconfigured, or mid-upgrade, the cache host may be unable to bootstrap the very updates it needs to recover.
If you still want this, it only works when localhost is listed in BindAddress (Step 9), and you should keep a tested fallback, such as a direct upstream sources file you can swap in, in case the proxy path fails.
- Remember the dependency: If the cache host is down, clients with a hard-coded proxy fail their updates. Monitor it like any other service.
Wrapping Up
You now have one Ubuntu host caching APT downloads for your whole network. Clients point at port 3142, you’ve picked a deliberate path for HTTPS repos, and acngtool keeps the disk in check.
For most homelabs and small fleets, apt-cacher-ng hits the sweet spot: almost no upkeep, a small disk footprint, and real bandwidth savings once the cache is warm. Reach for a full mirror only when you need offline or guaranteed availability.
| Step | Action | Applies To |
|---|---|---|
| 1–3 | Install apt-cacher-ng, confirm it listens on 3142 | Cache host |
| 4–5 | Review config, optionally move CacheDir | Cache host |
| 6–7 | Add Acquire::http::Proxy and verify hits in the log | Clients |
| 8 | Decide how HTTPS repos are handled | Both |
| 9 | Set BindAddress and ufw rules | Cache host |
| 10–11 | Check the report page, roll out to the fleet | Both |
| Ongoing | Expire old packages with acngtool | Cache host |