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.
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.
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.
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:
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.
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/
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:
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:
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:
This will bring up a VPS running Ubuntu 12.04 LTS. To make use of it, you can easily SSH into it:
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:
And if you want to stop and remove the guest machine and all traces of it, run the following command from the host machine:
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.
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up now
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!
I agree - I think the tutorial is misleading because there are no ways to make Virtualbox running 64bits machines in the DigitalOcean boxes, because of this VT-X flag not being set.
To answer a previous question, about the use of having a VM inside a VM. This is particularly useful in a continuous integration environment. For example, what I was trying to achieve on my big CI box was:
This kind of mechanism works perfectly fine usually. But I can’t use local VMs in DigitalOcean :(
This article is not up to date with the new hashicorp / vagrant website ^^
After wasting an hour on this I read all the comments and find out this tutorial is useless!! WTF DO, remove this tutorial!!
Either address the “guru meditation state” error, or remove the tutorial. I’ve found half a dozen threads related to this error and no posted solution. It’s fine if DigitalOcean’s kvm doesn’t support VirtualBox (I’ll survive), but it’s another to write a tutorial, get numerous support tickets about not being able to install vagrant, and refuse to answer those questions on the grounds that it is “outside the scope of support.” That’s worse than unhelpful. It’s borderline disrespectful of your customers’ time.
I noticed that the last link in this article is dead: https://www.digitalocean.com/community/tutorials/how-to-use-digitalocean-as-your-provider-in-vagrant-on-an-ubuntu-12-10
I think it’s supposed to point here instead: https://www.digitalocean.com/community/tutorials/how-to-use-digitalocean-as-your-provider-in-vagrant-on-an-ubuntu-12-10-vps
Question, if I deploy a vagrantfile that spins up a machine with the flask framework which uses say port 5001; would I be able to access this from my browser at home? thanks!
The vagrant deb download page has now been changed to: https://www.vagrantup.com/downloads.html
I have also been battling with this Gurumeditation state…Digital Ocean support told me it is beyond the scope of their support. Has anyone solved this yet? Below are the steps I have taken with multiple configurations
Then I get the Gurumeditation error … :-/
just tried this on an Ubuntu 14.04 droplet, with all combinations of 32/64bit host and guest, no dice. I keep getting this:
**The guest machine entered an invalid state while waiting for it to boot. Valid states are ‘starting, running’. The machine is in the ‘gurumeditation’ 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 upwhile the VirtualBox GUI is open.**
Some people are saying it works on digitalocean, some saying it doesn’t.
VirtualBox will not run in the KVM VMs that DigitalOcean provides. This tutorial should probably be removed.