BDD

Setting up VM’s with Vagrant on OSX

Vagrant

Vagrant is a awesome tool to setup repeatable development environments. Vagrant helps developers by introducing common configuration and building development environments across Mac OSX, Linux and Windows.

Requirements

To use vagrant on Mac OSX Mavericks, we need following

  • VirtualBox

Download VirtualBox for Mac OSX and install it by following instructions.

virtualbox

You will see something like this. You have now got VirtualBox on your Mac

  • Vagrant for OSX

Previously vagrant used to come up with RubyGems. You would have to just do

This method is no longer supported now, so if you have installed vagrant using RubyGems un-install it using

Now, Download vagrant.dmg file for Mac from official vagrant website

Complete the installation by following instructions, you will see something like this

vagrant

Now you have vagrant installed.

Boot VM’s with Vagrant

Now that, we have installed vagrant on our Mac. You can open i-Term Or Terminal and type

This should print version of the vagrant installed. You can now see what are the command line options are available for vagrant

My i-Term looks like this :

vagrant CLI

 

Add Vagrant Box CentOS

There are number of vagrant boxes available on vagrantboxes website. We will now use “CentOS 6.3 x86_64 minimal” box

Let’s now add this box and name it ‘CentOS’

This will create a “Vagrantfile” in your directory which we can modify accordingly

My i-Term window look like this:

vagrant_add

Vagrant UP

Now that, we got CentOS VM ready to boot. We can boot this VM by using ‘vagrant up’, this will run CentOS  machine in the VirtualBox.

This will take few minutes, be patient.

vagrant_up

 

Vagrant SSH

Now we have CentOS VM running in the virtualBox. We can ‘ssh’ into that VM and do crazy things. Now let’s ssh into machine and check if correct version of CentOS installed.

Look at these commands

vagrant_ssh

Once you done all work on this VM you can halt this VM

This will halt VM. There are plenty of command line options we can play with.

Conclusion

We can spin up multiple VM’s using vagrant and keeping development environment config very simple. Use Vagrant and have fun !