Starting with Vagrant on Ubuntu 14.10 - A Beginner's Guide
This tutorial will cover the installation of Vagrant on Ubuntu 14.10, explain the basics of this great virtualisation tool and will guide you trough the creation of your first Vagrant instance.
Why do you need Vagrant?
To start with, I am sure this must be first question in every beginner's mind, that Why do I need it? To answer this, Vagrant is a piece of software through which you can create and configure virtual development environments. It is an highly efficient tool for managing virtual machines via CLI. This increases your and your team's productivity and flexibility.
Here, machines are provisioned on top of any of the virtualization tool, i.e. VirtualBox, VMware, AWS, or of any other provider. Later, industry-standard provisioning tools such as shell scripts, Puppet or Chef, can be used to automatically install and configure software on the machine.
This simply means that you can get a easy to configure, reproducible, and portable work environments as and when you require.
How does it benefits?
Vagrant has benefits to developers, operations engineer, designers and more. Here the key is that Vagrant makes it really easy with the fact that there is no complication or using vim and loads of annoying command line stuff easy to run a development environment. Getting your first development virtual machine ready will take minutes. (Excluding box/image download time).
Once you have finished developing, you can check in your changes, ask your colleague to check them out, and then they run the code on the exact same machine. This even works if they are on any part of world and is platform independent i.e. regardless of whether they are on Windows, Linux or Apple OS X. It is safe to say goodbye to "works on my machine" bugs after using Vagrant.
You'll surely get to know the benefits better once you start using it. You can read more about benefits here.
Getting Started
Download & install the latest version of Vagrant & Virtual Box, by visiting Vagrant Downloads and VirtualBox Downloads. Usually, the newest version of VirtualBox will work fine, but you should verify the version compatibility with Vagrant, by checking the official Vagrant docs.
Since I am using Ubuntu 14.10 x86_64, I'll show you how to download & install them on it:
Download them by:
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.deb
wget http://download.virtualbox.org/virtualbox/4.3.22/virtualbox-4.3_4.3.22-98236~Ubuntu~raring_amd64.deb
Install them by:
sudo dpkg -i vagrant_1.7.2_x86_64.deb
sudo dpkg -i virtualbox-4.3_4.3.22-98236~Ubuntu~raring_amd64.deb
Here are some terms which you must understand before we run our first vagrant box:
Vagrant Box
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.
Providers
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.
Provisioners
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 Vagrantfile
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 in your virtual machine.
Creation of Instance
Create a test directory where we would be creating our first instance.
mkdir -p ~/Vagrant/test
cd ~/Vagrant/test
We'll be using Ubuntu 12.04 LTS (Precise Pangolin), which already has a "box" set up.
vagrant box add precise32 http://files.vagrantup.com/precise32.box
You see here the argument precise32 which is a nickname for the URL. The box is downloaded at ~/.vagrant.d/boxes. You can now create an instance:
vagrant init precise32
vagrant up
If all goes well, it will now be running. Below is how the very basic VagrantFile looks like:
Vagrant.configure(2) do |config|
config.vm.box = "precise32"
end
Please note- I have deleted the commented lines to avoid confusion.
If you want to get into this instance, via SSH, use this command:
vagrant ssh
Your instance is ready!
We'll learn more about Vagrant in the next tutorial.