
Boost Ubuntu Updates: How to Set Up an APT Caching Server with Apt-Cacher NG
If you manage multiple Ubuntu or Debian-based systems on a single network, you’ve likely noticed a recurring issue: each machine independently downloads the same package updates, consuming significant internet bandwidth and time. This is especially inefficient in development labs, office environments, or even a home with several Linux machines.
Fortunately, there is a powerful and straightforward solution: setting up a local APT caching server. By deploying a tool like Apt-Cacher NG, you can create a central proxy that downloads each package exactly once from the internet. Subsequent requests for that same package from any other machine on your network are then served instantly from the local cache, dramatically speeding up updates and saving bandwidth.
This guide will walk you through the simple process of installing and configuring an Apt-Cacher NG server on Ubuntu and pointing your client machines to it.
What is Apt-Cacher NG and Why Should You Use It?
Apt-Cacher NG is a caching proxy server specifically designed for APT (Advanced Package Tool) repositories. Think of it as a smart middleman for your system updates. When a client machine requests a package, the request goes to the Apt-Cacher NG server first. If the server has the package in its cache, it serves it directly. If not, it fetches the package from the official Ubuntu repositories, delivers it to the client, and stores a copy for future requests.
The primary benefits of this setup are clear:
- Massive Bandwidth Savings: A 100MB update is downloaded only once to your network, regardless of whether you have 2 or 200 machines needing it.
- Faster Updates and Installations: Serving packages from a local server is significantly faster than downloading them from the internet, especially for subsequent machines.
- Increased Network Efficiency: Frees up your internet connection for other critical tasks while updates are in progress.
Setting Up the Apt-Cacher NG Server
First, designate one of your Ubuntu machines to act as the server. This machine should be reliable and consistently powered on. A lightweight server, virtual machine, or even a dedicated desktop can work perfectly for this role.
Step 1: Install the Apt-Cacher NG Package
Installation is as simple as installing any other package. Open a terminal on your designated server machine and run the following commands:
sudo apt update
sudo apt install apt-cacher-ng
The package manager will handle the installation and start the service automatically.
Step 2: Verify the Service is Running
Once the installation is complete, it’s good practice to confirm that the Apt-Cacher NG service is active and running without errors. Use this command:
sudo systemctl status apt-cacher-ng
You should see output indicating the service is active (running). This confirms the server is operational and ready to accept connections.
Step 3: Identify the Server’s IP Address
You will need the local IP address of your new caching server to configure your client machines. Run one of the following commands to find it:
hostname -I
or
ip a
Look for the IP address associated with your primary network interface (e.g., eth0 or enp0s3). It will likely be in a format like 192.168.1.100 or 10.0.0.50. Take note of this IP address.
Configuring Client Machines to Use the Cache
Now that the server is running, you need to instruct all your other Ubuntu/Debian machines (the “clients”) to use it as their package proxy. This process is non-destructive and easily reversible.
On each client machine, you need to create a simple APT configuration file.
Step 1: Create a New Proxy Configuration File
Using a terminal on a client machine, create a new file in the /etc/apt/apt.conf.d/ directory. We’ll name it 00proxy for clarity.
sudo nano /etc/apt/apt.conf.d/00proxy
Step 2: Add the Proxy Configuration
Inside this new file, add the following single line. Be sure to replace YOUR_SERVER_IP with the actual IP address you noted in the previous section.
Acquire::http::Proxy "http://YOUR_SERVER_IP:3142";
The default port for Apt-Cacher NG is 3142. After adding the line, save the file and exit the editor (in nano, press Ctrl+X, then Y, then Enter).
Step 3: Test the Configuration
To apply the changes and test that the client can communicate with the server, simply run apt update:
sudo apt update
If the command completes successfully without any “failed to fetch” errors, your client is now configured to use the caching server. Repeat this client configuration on all other machines you want to use the cache.
Monitoring and Verifying Your Cache
How do you know it’s actually working? Apt-Cacher NG provides an easy-to-use web interface for monitoring its activity and statistics.
Simply open a web browser on any machine on your network and navigate to:
http://YOUR_SERVER_IP:3142
From there, you can click on the “Statistics Report and Configuration” link to see valuable data, including cache hits (requests served locally) and misses (requests fetched from the internet), as well as total bandwidth saved. This page provides definitive proof of the efficiency gains.
Actionable Security Tip: Firewall Configuration
If you are running a firewall on your server (like ufw), you must allow incoming traffic on port 3142 for the clients to be able to connect. To do this, run the following command on the server:
sudo ufw allow 3142/tcp
By investing just a few minutes to set up an Apt-Cacher NG server, you can create a more efficient, faster, and cost-effective network environment for all your Debian-based systems. It is a simple but powerful optimization for any system administrator or power user.
Source: https://kifarunix.com/how-to-setup-apt-caching-server-using-apt-cacher-ng-on-ubuntu-18-04/


