How to install Vagrant

Posted: 12 October 2015, Category: Coding

How to install Vagrant

These days web developers have a huge selection of ways to build their web development environment.

Development or local environment such as XAMPP, MAMP, WAMP, is a great way to start but what if you want to have your development the same as your production environment?

Or maybe you are just learning Ubuntu, Debian, CentOS, Fedora or some other Unix-like operating system and you need a playground to mess about with all the commands you have heard the cool Rails developers talking about.

Or perhaps you are a 'Windows' person but would like to develop your application on a Unix platform from your 'Windows' machine

Or maybe you would like the 'Mac' people and the 'Windows' people on your development team to work on an identical development environment no matter what OS they are using

Then virtualization is a great way to go, and Vagrant allows you to quickly and simply create a virtual development environment.

In this tutorial I will show you how to provision a virtual machine with Ubuntu Server 14.04 LTS as guest operating system using Vagrant installed on Virtualbox from Oracle

Both Vagrant and Virtualbox are completelly free and may be installed on every major operating system

1. Download Virtualbox

Head over to Virtualbox and download Virtualbox

2. Download Vagrant

Now head over to Vagrant and install the program using the appropriate installer or package for your operating system.

The installer should automatically add Vagrant to your system path so that the commands below may be run from any directory on the host terminal

If you encounter problems, try logging out and logging back in to your system (this is particularly so for Windows OS).

3. Check if Vagrant is installed

Open the terminal on your host system and type

  vagrant -v

This should return the version of Vagrant that is installed. In my case it's Vagrant 1.7.2

4. Install Vagrant box

The Atlas website allows you to search for and download a wide range of boxes. Just make sure to click on virtualbox provider before selecting one.

To install ubuntu/trusty64 as guest OS, run the following command from the host terminal window.

  vagrant box add ubuntu/trusty64

The Vagrantbox is another alternative offering a choice of over 280 boxes.

If you decide to use Vagrantbox you will need to provide title and url. In command below I used title amd64

  vagrant box add amd64

5. Remove installed Vagrant box

  vagrant box remove amd64

This command will remove installed vagrant box. Last parameter is the name of your vagrant box.

6. Remove certain version of Vagrant box

Let's say we have installed ubuntu/trusty64 (virtualbox, 20150609.0.10) and ubuntu/trusty64 (virtualbox, 20160107.1.0) and now you want to remove one of them.

  vagrant box remove ubuntu/trusty64 --box-version=20160107.1.0

--box-version flag allows you to select box version you wish to delete.

7. List installed Vagrant boxes

  vagrant box list

My terminal returns ubuntu/trusty64 (virtualbox, 20150609.0.10) as I installed vagrant box using vagrant box add ubuntu/trusty64 command

8. Create a Virtual Development Environment

Create a folder in a convenient location such as on the desktop.

Navigate/cd into this folder and execute vagrant init {name of box} from the host command line

  vagrant init ubuntu/trusty64

This command will create a Vagrantfile file which contains the primary configuration for your Vagrant virtual development environment. It is written in Ruby, but there is no need to know Ruby.

9. Create Vagrant box

  vagrant up

The vagrant up command will create and configure the Vagrant box according to the settings in your Vagrant file. This command is also used to restart the Vagrant box.

10. Login

  vagrant ssh

The command vagrant ssh will connect you to the Vagrant box as user 'vagrant'. Now you have opportunity to execute all the Ubuntu commands you ever wanted to try. The command whoami, for example will return 'vagrant', and hostname -I will return something like

11. Logout


Typing exit will log you out of your Vagrant box.

12. Suspending Vagrant box

  vagrant suspend

Executing vagrant suspend will stop the virtual machine and save the current running state. Use vagrant up to start up the Vagrant box again and continue from where you left off.

13. Halting Vagrant box

  vagrant halt

The command vagrant halt will completely shut down the Vagrant box. Use vagrant up to restart

14. Destroying Vagrant box

  vagrant destroy

The command vagrant destroy will completely remove and delete all traces of the Vagrant box from your system.


That’s all it takes to get up and running with Vagrant. The above tutorial contains just the basic commands for setting up Vagrant and installing/running a Vagrant box. It is a great way to learn how to set up and administer a server without worry. If things go disastrously wrong, you can easily destroy the Vagrant box and start again. I started using Vagrant for Ruby on Rails development. I then almost immediatelly started using it for PHP development instead of above mentioned XAMPP and WAMP servers.

If you are looking for Cloud Hosting with powerful SSD cloud server and ssh access, checkout DigitalOcean


I hope this short tutorial gave you a quick introduction to Vagrant. Please feel free to contact me if you have any questions, comments or suggestions.

Back to Blog page

Blog categories

Twitter feed

(about 20 hours ago)
Sortable Drag and Drop

(5 days ago)
30 interesting commands for the Linux shell -

(8 days ago)
Testing Emails in Development with Mailcatcher

(10 days ago)
Recurring Events with FullCalendar via @driftingruby

Top of page