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.
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.
Virtualbox is the virtualization software used by Vagrant:
$ sudo apt-get install virtualbox
$ 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.
$ sudo apt-get install linux-headers-$(uname -r)
$ sudo dpkg-reconfigure virtualbox-dkms
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
$ 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 `vagrantup.com` for more information on using Vagrant.
$ 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 box. 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
$ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2 vagrant@precise32:~$
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!