Seb's Blog

DevOps Code.

Installing Vagrant on Ubuntu 12.10

Vagrant is open-source software for creating and configuring virtual development environments. I started using it because I often need reproductible testing or installation environments, and using my workstation for this purpose usually resulted in breaking my development environment, wasting my time in OS re-installation, and being unsatisfied because of non-reproductible behaviors.

Why Reproductibe Environments are Essentials

Without a reproductible environment that can be setup rapidly, testing installation or deployment scripts almost always ends up in breaking my working environment and makes me less efficient.

Install Virtualbox

Virtualbox is the virtualization software used by Vagrant:

$ sudo apt-get install virtualbox

Install Vagrant

$ sudo apt-get install vagrant

Unless you've already installed you kernel headers, it shouldn't go without a hitch when executing the post-install scripts:

First Installation: checking all kernels...
Building only for 3.5.0-25-generic
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.
 * Stopping VirtualBox kernel modules                                   [ OK ] 
 * Starting VirtualBox kernel modules
 * No suitable module for running kernel found                          [fail]
invoke-rc.d: initscript virtualbox, action "restart" failed.

What happens here is that the virtualization technology used by VirtualBox needs specific kernel modules to be loaded, and these kernel modules are not built unless kernel headers are installed.

Install Kernel headers

$ sudo apt-get install linux-headers-$(uname -r)

Reconfigure Virtualbox DKMS

$ sudo dpkg-reconfigure virtualbox-dkms

Get your first Vagrant machine up and running

Download a base image

$ vagrant box add precise32

Configure a project to use the base image

$ vagrant init precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`` for more information on using Vagrant.

Start the environment

$ vagrant up
[default] Importing base box 'precise32'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the

Guest Additions Version: 4.2.0
VirtualBox Version: 4.1.18
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant

Connect through SSH

$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from

Et Voila :) Anything can now happen to this newly created machine, including the installation of broken packages or destructive integration tests, without breaking your working environment!

blog comments powered by Disqus