The following procedure describes How To install the Apt-Cacher-NG package in Ubuntu Linux.
(published at: http://ubuntuforums.org/showthread.php?t=981085)
Apt-Cacher-ng <http://www.unix-ag.uni-kl.de/~bloch/acng/> is a software package that keeps a cache on the disk, of Debian Packages and Release files.
When an apt-get issues a request for a file, Apt-Cacher intercepts it and if the file is already in the cache it serves it to the client immediately, otherwise it fetches the file from the Internet, saves it on disk, and then serves it to the client. This means that each package needs to be downloaded only once, in order to let several Debian machines to use it afterwards.
Apt-Cacher-NG does not require an interpreter, nor a web server.
It does not: fork after server startup; create flag files; flock() files.
It uses native system functions (mmap, sendfile) to operate with few overhead.
1. Install Apt-Cacher-NG on the server machine
1.1. Download & Install from Ubuntu pool
sudo apt-get install apt-cacher-ng
1.2 RECOMMENDED: build & install from latest sources
sudo apt-get install libbz2-dev libfuse-dev # install support apps
# goto <http://ftp.debian.org/debian/pool/main/a/apt-cacher-ng/?C=M;O=D> and download the newest source:
cd $(mktemp -d) ; # create a temp dir and cd to it
wget http://ftp.debian.org/debian/pool/ma....6.orig.tar.gz
# get the sources from the debian/ubuntu repositories
apt-get source apt-cacher-ng
cd $(ls -d apt-cacher-ng-*/)
# update package info to new version
(export DEBFULLNAME='dummy';export DEBEMAIL='dummy <dummy@example.com>';uupdate --upstream-version 0.4.6 ../apt-cacher-ng_0.4.6.orig.tar.gz)
cd ../"$(dpkg-parsechangelog | sed -n 's/^Source: //p')-0.4.6"
# customize maintainer data
grep '^Maintainer\|^Uploaders\|XSBC-Original-Maintainer' debian/control
sed -i '/^Maintainer/s/: .*/: dummy <dummy@example.com>/;/^Uploaders/s/: .*/: dummy <dummy@example.com>/;/XSBC-Original-Maintainer/d' debian/control;
# adjust runlevel arguments
sed -i 's/2 3 5/2 3 4 5/;s/0 6/0 1 6/' debian/apt-cacher-ng/etc/init.d/apt-cacher-ng # grep '2 3\|0 ' debian/apt-cacher-ng/etc/init.d/apt-cacher-ng
sed -i 's/2 3 5/2 3 4 5/;s/0 6/0 1 6/' debian/apt-cacher-ng.init # grep '2 3\|0 ' debian/apt-cacher-ng.init
# build the new package
(export DEBFULLNAME='dummy';export DEBEMAIL='dummy@example.com';debuild -i -us -uc);
cd .. ; cp -avf apt-cacher-ng*deb /home/ftp/it-sw-bin/
sudo apt-get purge libbz2-dev libfuse-dev # remove support apps
sudo dpkg -i apt-cacher-ng*deb && echo "apt-cacher-ng hold" | sudo dpkg --set-selections
2. Configure (apply to server and each client machine)
# search & replace 192.168.1.100 by the IP of the machine that will act as apt-cacher-ng server
# enable proxy usage by apt-get, aptitude, etc.
echo 'Acquire::http { Proxy "http://192.168.1.100:3142"; };' | sudo tee /etc/apt/apt.conf.d/01apt-cacher-ng-proxy
# enable proxy usage by Synaptic
sudo grep --color -i 'proxy' /root/.synaptic/synaptic.conf || sudo nano /root/.synaptic/synaptic.conf
# ...and overwrite the last line }; with:
useProxy "1";
httpProxy "192.168.1.100";
httpProxyPort "3142";
ftpProxy "192.168.1.100";
ftpProxyPort "3142";
noProxy "";
};
sudo grep --color -i 'proxy' /root/.synaptic/synaptic.conf
# ...or enable proxy using the Synaptic GUI:
a) In Synaptic go to "Settings->Preferences->Network"
b) click "Manual Proxy Configuration"
c) enter:
HTTP Proxy: 192.168.1.100 3142
FTP Proxy: 192.168.1.100 3142
Click OK
Click Reload
sudo apt-get update # now update the apt-get system
3. Import local .deb files
test -x /var/cache/apt-cacher-ng/_import || sudo mkdir -p -m 2755 /var/cache/apt-cacher-ng/_import
sudo mv -uf /var/cache/apt/archives/*.deb /var/cache/apt-cacher-ng/_import/
sudo chown -R apt-cacher-ng.apt-cacher-ng /var/cache/apt-cacher-ng/_import
# start import at: <http://192.168.1.100:3142/acng-report.html?doImport=Start+Import#bottom>
# cleanup and update apt cache index files
sudo rm -fr \
/var/cache/apt-cacher-ng/_import \
/var/cache/apt/archives/*.deb \
/var/cache/apt/*cache.bin \
/var/lib/apt/lists/*Packages \
/var/lib/apt/lists/*Sources
sudo apt-get update
4. To stop using the proxy
# disable proxy usage
sudo rm /etc/apt/apt.conf.d/01apt-cacher-ng-proxy # by apt-get
sudo sed -i '/useProxy/s/1/0/' /root/.synaptic/synaptic.conf # by synaptic
sudo /etc/init.d/apt-cacher-ng stop # stop
sudo apt-get update
# do click Reload in the Synaptic GUI
# to completly remove the proxy from your system
#sudo apt-get purge apt-cacher-ng
#sudo rm -fr /var/cache/apt-cacher-ng
5. Other: optional customizations
# days before deleting unreferenced files
grep ExTreshold /etc/apt-cacher-ng/acng.conf
sudo sed -i 's/^ExTreshold:.*/ExTreshold: 15/' /etc/apt-cacher-ng/acng.conf
6. Dashboard & manual
# see the apt-cacher-ng dashboard at: <http://192.168.1.100:3142/acng-report.html>
# see apt-cacher-ng User Manual at: (right click at the link and open with your browser): <file:///usr/share/doc/apt-cacher-ng/html/index.html>
# Howtos: <http://www.unix-ag.uni-kl.de/~bloch/acng/html/howtos.html>
## -- END --
Bookmarks