Tutorial

How To Install Vagrant on a VPS Running Ubuntu 12.04

How To Install Vagrant on a VPS Running Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About Vagrant

Vagrant is a great open source software for configuring and deploying multiple development environments. It works on Linux, Mac OS X, or Windows and although by default it uses VirtualBox for managing the virtualization, it can be used with other providers such as VMware or AWS.

The good thing about Vagrant is that by using a central place for configuration, you can deploy virtual private machines packed with all you need. Moreover, it allows team members to run multiple environments with the same exact configuration.

Installation

To install Vagrant on your cloud server, you need to download and run the installation kit. Before going further, be sure that you have dpkg and Virtual box installed:

sudo apt-get install dpkg-dev virtualbox-dkms

Go to the downloads page of Vagrant and check for the latest release. Once you are looking at the different versions of the latest release, right click over the one with the .deb extension and copy the link address. Then head back to your terminal and run the following command:

wget http://files.vagrantup.com/packages/0219bb87725aac28a97c0e924c310cc97831fd9d/vagrant_1.2.4_i686.deb

Replace the URL you see above (following the wget command) with the one you just copied. This will download Vagrant to your system. Next, install the package with the following command:

dpkg -i vagrant_1.2.4_i686.deb

Make sure you replace the file name above with the one that was downloaded before. Next up, you’ll need to take care a couple of more things. First, install Kernel headers:

sudo apt-get install linux-headers-$(uname -r)

Then, reconfigure the VirtualBox DKMS:

sudo dpkg-reconfigure virtualbox-dkms

And now you are ready for the good stuff.

Getting Started with Vagrant

The idea behind Vagrant is to be able to quickly deploy development environments. That means you can set up some basic configuration once and then you or your team members can quickly deploy virtual private machines with identical software and settings. Part of what this makes work are virtual images called boxes.

So let’s install a box that can be used by multiple Vagrant environments later on. This is done with the vagrant box add command. Run the following command to install the precise32 box from the Vagrant website:

vagrant box add precise32 http://files.vagrantup.com/precise32.box

You should get the following success message: "Successfully added box 'precise32' with provider 'virtualbox'!". Now you have an image for a VPS with the Ubuntu 12.04 operating system on it.

Each project you run is created using such a box. This means that if you have 3 different projects based on the same box, changing one or another does not affect the original box. Now let’s set up a first project that will be deployed based on the precise32 box we just added to Vagrant.

Create a root directory for your project and navigate in it:

mkdir test_project
cd test_project

Next, run the initialization command:

vagrant init

This will create a Vagrantfile in this folder which will be the central file for your project configuration. But before we can deploy the guest machine using the box we just added, edit the Vagrantfile:

nano Vagrantfile

Find the following line:

config.vm.box = "base"

And replace it with:

config.vm.box = "precise32"

This will tell it to use this new box. Save the file and exit. Now you can deploy the guest machine with the following command:

vagrant up

This will bring up a VPS running Ubuntu 12.04 LTS. To make use of it, you can easily SSH into it:

vagrant ssh

This will put you directly into an SSH session with the new guest machine. A cool thing is that by default, Vagrant will share the project root folder from the host machine (the one containing the Vagrantfile) with a folder on the guest machine, /vagrant. This means that you can save files on the guest machine that will remain on the host, and vice versa.

After you are done working with the guest machine, you can exit and go back to the host with the following command:

exit

And if you want to stop and remove the guest machine and all traces of it, run the following command from the host machine:

vagrant destroy

Please note that the files that were synchronized with the host machine will not be removed from the host. Additionally, you can redeploy the guest machine again for this configuration using the same vagrant up command.

Conclusion

In this tutorial, you learned how to set up Vagrant and how to configure a simple Ubuntu VPS. In the next tutorial, we will go a bit deeper and talk more about boxes, operating systems and the automatic installation of various software on the guest machines.

Vagrant—Article #1

Vagrant—Article #2

Vagrant—Article #3

Article Submitted by: Danny

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

“E: Unable to locate package virtualbox-dkms” … And its ubuntu 13.04 ! How to solve this ?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
August 4, 2013

@prism: Try running ‘sudo apt-get update’ first.

what is the point of running VM in a VM? Just curious, I like the tutorisl though.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
October 21, 2013

@titelskibreg: One purpose would be to have multiple development environments on a single vps easily.

@Kamal Nasser … i dont think this will work on a VPS ? … have you got it to work ?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 9, 2014

@alston.fernandez: I don’t see why it won’t. I’ve never used Vagrant, though.

I followed your instruction installed virtualbox and vagrant on ubuntu 12.04 on DO, but when i “vagrant up” the VM, it always says that

“The guest machine entered an invalid state while waiting for it to boot. Valid states are ‘starting, running’. The machine is in the ‘poweroff’ state. Please verify everything is configured properly and try again.”

@steven.ly147 I think we need to enable VT-X (virtualization). I am getting the same error. I am wondering on how to enable VT-X still. If you have resolved your issue, let me know.

Thanks, Shyam http://about.me/shyam_visamsetty

Anybody found a solution? I also get that error message

The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.

If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.

I wanted to test a vagrant (and my current connection is of no use), thought I’d use a vagrant so it goes faster than 13kb/s to download requirements.

I’ll try to use this instead: vagrant-digitalocean on github

VirtualBox will not run in the KVM VMs that DigitalOcean provides. This tutorial should probably be removed.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.