Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Setting up an ëApt-Cache\' Server Using ëApt-Cacher-NG\' in Ubuntu 14.04 Server
Apt-Cacher-NG is a proxy server for Linux package repositories that caches downloaded packages locally. This reduces bandwidth usage and speeds up package installations across multiple Ubuntu systems by serving cached packages instead of downloading them repeatedly from remote repositories.
How Apt-Cacher-NG Works
When a client requests a package, Apt-Cacher-NG checks if it exists in the local cache. If found, it serves the cached version immediately. If not, it downloads the package from the upstream repository, caches it locally, and then serves it to the client. All subsequent requests for the same package are served from the cache.
Installation Methods
Method 1: Manual Installation
Install the Apt-Cacher-NG package on your Ubuntu 14.04 server:
sudo apt-get update sudo apt-get install apt-cacher-ng
Configuration
Edit the main configuration file to customize settings:
sudo nano /etc/apt-cacher-ng/acng.conf
Key configuration options:
# Cache directory (default is /var/cache/apt-cacher-ng) CacheDir: /var/cache/apt-cacher-ng # Allowed networks (uncomment and modify as needed) # AllowUserPorts: 0 # DeniedUsers: # Port number (default is 3142) Port: 3142
Restart the service to apply changes:
sudo service apt-cacher-ng restart
Client Configuration
Configure client machines to use the cache server by modifying their sources.list file:
sudo nano /etc/apt/sources.list
Replace the original Ubuntu repository URLs with the cached versions:
# Original line: # deb http://archive.ubuntu.com/ubuntu trusty main restricted # Replace with (substitute YOUR_SERVER_IP): deb http://YOUR_SERVER_IP:3142/archive.ubuntu.com/ubuntu trusty main restricted deb http://YOUR_SERVER_IP:3142/archive.ubuntu.com/ubuntu trusty universe multiverse
Update the package cache on client machines:
sudo apt-get update
Method 2: Docker Container
Run Apt-Cacher-NG using Docker for easier deployment and management:
# Pull and run the apt-cacher-ng container
sudo docker run -d --name apt-cacher-ng \
-p 3142:3142 \
-v /var/cache/apt-cacher-ng:/var/cache/apt-cacher-ng \
sameersbn/apt-cacher-ng
Client configuration remains the same as Method 1, using the Docker host's IP address.
Management and Monitoring
Access the web interface for monitoring cache statistics and usage:
# Open in browser: http://YOUR_SERVER_IP:3142/acng-report.html
Perform regular maintenance to clean up old cached packages:
# Clean expired packages from cache sudo apt-get autoclean # Update the cache server itself sudo apt-get update && sudo apt-get upgrade
Advantages
Bandwidth savings Packages are downloaded once and served to multiple clients
Faster installations Local cache serves packages at LAN speeds
Reduced internet dependency Common packages available even during internet outages
Web interface Easy monitoring and management through browser
Conclusion
Setting up Apt-Cacher-NG creates an efficient package caching solution for Ubuntu networks. By serving frequently requested packages from a local cache, it significantly reduces bandwidth usage and accelerates package installations across multiple systems. The web interface provides easy monitoring and management capabilities.
