Caching APT Packages in Ubuntu 14.04 with Squid

thumb image-post

Title says it all. If you're looking for the quickest way to start caching APT requests in Ubuntu, this should set you up.

#!/bin/bash
#
# Installs Squid proxy / cache and points Apt to it.
# Cached packages are located at: /var/spool/squid

# Install Squid
apt-get install -y squid

# Change this to the subnet your box runs on
echo "acl localnet src 10.0.0.0/16" >> /etc/squid/squid.conf

# Cache files up to 4GB
echo "maximum_object_size 4000 MB" >> /etc/squid/squid.conf

# Allow a total cache size of 10GB
echo "cache_dir ufs /var/spool/squid 10000 16 256" >> /etc/squid/squid.conf

service squid restart

# Point apt to Squid cache
echo "Acquire { Retries \"0\"; HTTP { Proxy \"http://localhost:3128\"; }; };" >> /etc/apt/apt.conf