Add ability to cache apt-get programs



From Caching apt-get install results

All credit to @winksaville, this is a feature I would really like as well.

It would speed up builds immensely.

Caching apt-get packages

+1 for this. I was wondering how I could do this earlier. Especially helpful when you need to run an apt-get update before installing a package.


Thank you for your feedback—we’ll see what we can do here.


This should work >

    - "~/.apt-cache"
    - sudo rm -rf /var/cache/apt/archives && sudo ln -s ~/.apt-cache /var/cache/apt/archives && mkdir -p ~/.apt-cache/partial


Or set the cache dir when you call it:

- sudo apt-get -o dir::cache::archives="/home/ubuntu/aptcache" update; sudo apt-get -o dir::cache::archives="/home/ubuntu/aptcache" install -y libmemcached-dev gettext cowsay


I’m not sure if this caches the update bit, since the lists are stored somewhere else if I am not mistaken. I may be silly and haven’t timed the overhead of update properly, but I have this more complicated approach


set -e

pkgs=(git curl libcurl3 libcurl3-gnutls)

# Work from the directory CI will cache
mkdir -p ~/cache/deb
cd ~/cache/deb

# check we have a deb for each package
for pkg in "${pkgs[@]}"; do
    if ! ls | grep "^${pkg}"; then

set -x

if [ ${useCache} == true ]; then
    sudo dpkg -i *.deb
    exit 0

sudo apt-get update
sudo apt-get install --reinstall "${pkgs[@]}"

cp -v /var/cache/apt/archives/*.deb ~/cache/deb/

(we have ~/cache in our cached_directories)



I’ve just published a guide which helps improve apt-get installs on
CCI, please try it out and let me know how we can improve it!


Your guide seems to solve this for CircleCI 1.0. Is there an equivalent for 2.0?


The same would work in 2.0 if you are using a Debian-based environment. Ideally, before trying to employ this, you would simply use a Docker image that has the packages installed and not installing them on the fly.