How to install and use Vagrant
When developing an application or a website, probably it happened to you to have a bug in a given environment (production or staging) that you could not reproduce locally on your workstation. Vagrant will allow you to use virtualization to have exactly the same environment as your servers.
So Vagrant is a great tool when two or more developers want to use the same virtual environment or when operation team want to test infrastructure management scripts and other tools on a local environment and deploy to production using the same configuration.
Note that we will be using Debian as an os.
First you will need Virtualbox and dpkg:
sudo apt-get install dpkg-dev virtualbox-dkms
then download the last Vagrant version, copy the link from the download page : https://www.vagrantup.com/downloads-archive.html
dpkg -i vagrant_1.7.1_i686.deb
an update your Linux headers:
sudo apt-get install linux-headers-$(uname -r)
Finally tell your OS to configure the virtualbox library:
sudo dpkg-reconfigure virtualbox-dkms
When using vagrant you will be able to create rapidly a virtual machine or a container from a box.
A box is a virtual image, you can use the official boxes repository where you can find images created by Vagrant community.
In this tutorial we are going to choose Ubuntu Precise 32bit box:
vagrant box add precise32 http://files.vagrantup.com/precise32.box
This will download and install a box and install it. This operation could take time, it depends on your connection speed. You will have a virtual image installed on your system.
The installed environment is isolated so don’t worry 🙂
other boxes are available here.
After hitting enter, you will be able to see something similar to this (if everything is good):
Downloading or copying the box... Extracting box...te: 191k/s, Estimated time remaining: 0:00:01)) Successfully added box 'precise32' with provider 'virtualbox'!
You image is installed, now we are going to create the project folder:
mkdir project cd project
We will enable Vagrant:
A file called Vagrantfile will be created, this file contains a configuration of the Vagrant container.
To use the container that we called precise32, just change :
config.vm.box = "base"
config.vm.box = "pecise32"
then deploy it:
Your virtual machine is running, you can login using ssh to use it:
You will see something similar to this:
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686) * Documentation: https://help.ubuntu.com/ New release '14.04.2 LTS' available. Run 'do-release-upgrade' to upgrade to it. Welcome to your Vagrant-built virtual machine. Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
Excellent! No ?
I think that now, you can answer yourself about “Why should I use Vagrant instead of just Virtualbox?”
In the next tutorial you will learn other interesting things about Vagrant like how to automate the creation of a development environment. You can subscribe to stay updated.