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.
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
1 |
$ gem install vagrant |
This method is no longer supported now, so if you have installed vagrant using RubyGems un-install it using
1 |
$ gem uninstall vagrant |
Now, Download vagrant.dmg file for Mac from official vagrant website
Complete the installation by following instructions, you will see something like this
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
1 |
$ vagrant -v |
This should print version of the vagrant installed. You can now see what are the command line options are available for vagrant
1 |
$ vagrant help |
My i-Term looks like this :
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’
1 2 3 |
$ vagrant box add CentOS https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box $ vagrant init CentOS |
This will create a “Vagrantfile” in your directory which we can modify accordingly
My i-Term window look like this:
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.
1 |
$ vagrant up |
This will take few minutes, be patient.
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.
1 |
$ vagrant ssh |
Look at these commands
Once you done all work on this VM you can halt this VM
1 |
$ vagrant halt |
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 !