Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.
If you are a developer, Vagrant will isolate dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of the tools you are used to working with (editors, browsers, debuggers, etc.). Once you or someone else creates a single Vagrantfile, you just need to ~$ vagrant up and everything is installed and configured for you to work. Other members of your team create their development environments from the same configuration, so whether you are working on Linux, Mac OS X, or Windows, all your team members are running code in the same environment, against the same dependencies, all configured the same way. Say goodbye to “works on my machine” bugs.
~$ wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb
~$ wget https://download.virtualbox.org/virtualbox/5.2.6/virtualbox-5.2_5.2.6-120293~Ubuntu~xenial_amd64.deb
Install them by:
~$ sudo dpkg -i vagrant_2.0.1_x86_64.deb
~$ sudo dpkg -i virtualbox-5.2_5.2.6-120293~Ubuntu~xenial_amd64.deb
A box is basically a package containing a representation of a virtual machine running a specific operating system. To be more simple, it is a base image of any Operating System or Kernel. It may be for a specific Provider.
For example: https://app.vagrantup.com/boxes/search
The Provider is the piece of software responsible for creating and managing the virtual machines used by Vagrant. The main providers are Virtualbox and VMware, but the default one is VirtualBox since it’s free and open source.
Provisioner will do some task(s) using the VM instance already provided. The provisioners are used to set up the virtual server, installing all necessary software and executing different tasks. The most used provisioners are : Puppet, Chef, and Ansible. Shell Script is also a very common option. You can find more information about vagrant provisioners here.
The basic vagrant configuration is based in one file, the Vagrantfile. It shall be placed in your repository root. In this file you will define which base box you want a box is, basically, a package with an operational system to be run on your virtual machine.
After the installation is done, let us download one box from https://app.vagrantup.com/boxes/search with below commands
~$ mkdir vagrant-test
~$ cd vagrant-test
Let us command our first vagrant command: vagrant init
~$ vagrant init
It will create a file: Vagrantfile
Let us edit it:
~$ nano Vagrantfile
That is Ruby!
find config.vm.box = ‘base’ and change base with a image name on https://app.vagrantup.com/boxes/search
For example config.vm.box = “ubuntu/trusty64”
So it is basically
Vagrant.configure(“2”) do |config|
config.vm.box = “ubuntu/trusty64”
or you can run the below command instead of changing Vagrantfile
~$ vagrant init ubuntu/trusty64
Then the final command for provisioning:
~$ vagrant up
If it gives error execute with sudo!
It will take some time to finalize it.
After it is done when you check your VirtualBox you will see there is an virtual client running.
The default username is vagrant and password is also vagrant
But you can easily reach the virtual client from host (without knowing username/password) with below ssh command:
~$ vagrant ssh
Don’t forget: To run the commands you should be in the folder! If you have another VM then you should change folder (cd ….) to execute them!
Congratulations! You have a full box in a very short time!