Vagrant: virtualization your development environments Linux 21.03.2014

vagrant.png Vagrant is a powerful tool for creating, managing, and working with virtualized development environments. It's very easy as to start new a virtual environment for each project as destroy one. Project's dependencies and requirements are isolated, and don't interfere.

Vagrant provides simple command-line interface to configure virtual environment and storing configuration in simple text files. Likewise, vagrant allows syncing folders between host and virtual box without hassle.

Vagrant uses providers to integrate with the third-party virtualization software. The default provider is Oracle's VirtualBox however, there are providers to work with Amazon Web Services and VMware Fusion.

Launching a blank virtual machine is not very useful in some cases, so Vagrant supports provisioning virtual machines through the use of provisioners. There are a handful of provisioners for the most common choices supported out of the box with Vagrant. Provisioners allow you to easily setup your virtual machine with everything it needs to run your software. Most popular provisioners are Chef and Puppet.

More benefit of using Vagrant.

I am going to install Vagrant on Arch Linux.

yaourt -S virtualbox vagrant

Instruction for Ubuntu

sudo apt-get install virtualbox
sudo apt-get install linux-headers-$(uname -r)
sudo dpkg-reconfigure virtualbox-dkms
sudo apt-get install vagrant

Each virtual machine starts with what Vagrant calls a basebox. This is a specially packaged version of an operating system with some specific configurations in place.

The public assecible list of baseboxes is at

Let's add basebox with Lucid

vagrant box add lucid64

Vagrant will download base box and store it in ~/.vagrant

Now there is one box installed

vagrant box list

If you want to remove the box use next subcommand. We need to provide the name of the box and the provider as last parameter.

vagrant box remove lucid64 virtualbox

Create a working directory. This folder will contains Vagrantfile with configurations and files/folders which will be shared between host and virtual box.

cd ~/projects/
mkdir -p vboxes/project1
cd vboxes/project1

Next we need to init box and create Vagrantfile with configurations.

vagrant init lucid64 

Boot the virtual machine

vagrant up

After the box has started, Vagrant will add the local folder to virtual box as /vagrant.

Let's connect to virtaul box

vagrant ssh

Command bellow will show ssh settings.

vagrant ssh-config

Add next string to your Vagrantfile if you wanna to run webserver on your virtual box.

config.vm.forward_port 80, 8080

This statement will forward port 8080 on Host to 80 on the virtual box.

We can use the following in our Vagrantfile to sync more folders if we wish.

config.vm.synced_folder "/home/proft/docs/" "/home/user/docs"

The first parameter is the path to the folder on our machine, the second being the mount point on the virtual box.

After update you should restart Vagrant

vagratn reload

Status of the virtual box

vagrant status

Suspend the virtual box

vagrant suspend

Resume the virtual box

vagrant resume

Halt the virtual box

vagrant halt

Useful extensions

  • Veewee is a tool for easily (and repeatedly) building custom Vagrant base boxes, KVMs, and virtual machine images;
  • vagrant-vbguest a Vagrant plugin to keep your VirtualBox Guest Additions up to date;

Useful links