What is Vagrant?

Vagrant is an open-source virtualization manager, used for managing VM(Virtual Machine) and their configurations with few commands.

It is supported by VirtualBox, Docker, Hyper-V as well as VMWare virtualization. Vagrants helps managing the configurations of VM created using any of the mentioned virtualization. Its available for Mac OS X, Windows, Debian and Centos.

From WikipediaVagrant is an open-source software product for building and maintaining portable virtual development environments. The core idea behind its creation lies in the fact that the environment maintenance becomes increasingly difficult in a large project with multiple technical stacks. Vagrant manages all the necessary configurations for the developers in order to avoid the unnecessary maintenance and setup time, and increases development productivity.

Why Vagrant?

Consider you need a development environment setup. Using Vagrant, you can set it up in no time. And the best thing is that you just need to have very few and basic knowledge of computer networks. If you are well versed with the Vagrant setup, you can use the same setup for production too.

And best of all, its quite easy to setup, and safe use & re-use.

Install Vagrant with VirtualBox support

  1. Download VirtualBox from https://www.virtualbox.org/wiki/Downloads (“platform packages”) and install it.
  2. Next download Vagrant at https://www.vagrantup.com/downloads.html as per your OS preference, and install the package.

Managing VMs:

STARTING YOUR FIRST VM

Setting up and starting a VM is so simple that it will take not more than 5 mins. An example below is to download Centos image, install and start it:

~ > mkdir centos-vm && cd centos-vm

~ > vagrant box add centos https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
==> box: Adding box 'centos' (v0) for provider:
    box: Downloading: https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
==> box: Successfully added box 'centos' (v0) for 'virtualbox'!

~ > vagrant init centos
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

 

Thats it! Your VM with Centos is now ready to be used. Wasn’t it easy?

Note: You can get list of other Vagrant files for other OS at: http://www.vagrantbox.es/

ACCESSING THE VM

The command is ‘vagrant ssh’ to login the VM.

~/V/centos-vm > vagrant ssh
Last login: Mon Mar 20 13:49:26 2017 from 10.0.2.2
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS release 6.7 (Final)
[vagrant@localhost ~]$

 

SHUTTING DOWN THE VM

The command is ‘vagrant halt’ to shutdown the VM.

~/V/centos-vm > vagrant halt
==> default: Attempting graceful shutdown of VM...

 

DELETING THE VM

The command is ‘vagrant destroy’ to delete the VM.

~/V/centos-vm > vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Destroying VM and associated drives...
~/V/centos-vm >

 

Leave a Reply