Ahti Kitsik
Building develper tools. Python, Java, JavaScript.

writings about @ahtik

Caching Debian and Python packages in Vagrant VMs

By Ahti Kitsik, 20 Sep 2013

There's a trick to speed up your Vagrant VM creation process by providing caches for Debian (or Ubuntu) and Python that are **outside** the VM.

First, create a local dir, let's say "/ext/hostcache". Then edit your Vagrantfile to contain the following config:

 Vagrant.configure("2") do |config|
   config.vm.define :yourhostname0001 do |c|
   c.vm.provision :shell, :inline => <<STRING
     echo "dir::cache::archives /opt/cache/apt;" | sudo tee /etc/apt/apt.conf.d/80myhostcache > /dev/null
     if ! grep "PIP_DOWNLOAD_CACHE" /etc/environment > /dev/null; then
         echo "PIP_DOWNLOAD_CACHE=/opt/cache/pip"|sudo tee -a /etc/environment>/dev/null;
     fi
 STRING
 c.vm.synced_folder "/ext/hostcache", "/opt/cache", extra: 'dmode=777,fmode=777'

Enjoy super-fast Vagrant VM provisionings!

@ahtik is on twitter!