Vagrant – First steps

For my latest work with the tesseract-ocr engine, I needed to set up a C++ development environment. Working with the GNU CC under Linux is not as painful and complex as it can be under Windows which I am currently running as my main OS. Additionally, I needed to be able to work on multiple machines. If you are looking for a way to synchronize development environments across different machines and workplaces, Vagrant is definitely worth a look. It runs under Linux, Mac OS X and Windows.

This post covers the set up of a development machine running Ubuntu with the basic GNU Compiler Collection installed.

Vagrant does not provide its own virtualization technology, instead it runs on top of the most common providers such as VirtualBox, VMWare or even AWS. Vagrant handles the process of downloading and installing an operating system, installing and configuring the required software on that machine and also simplifies the way that machine can be shared with collaborators e.g. via a SCM.

Installation

At first, we need to download a virtualizing software. I already got Oracles’s VirtualBox installed, which is why I chose it as my Vagrant virtualization provider. It is freely available as OpenSource software for both personal and enterprise use and can be easily installed from here.

Once we got our virtualization stack running, we can download Vagrant from vagrantup.com and run the installer.

Configuration and first launch

To initialze Vagrant, we create a new directory for our project (note that this is most likely going to be the root directory for our repository). Open a terminal, navigate into that directory and run the command

to create an initial Vagrantfile. The Vagrantfile tells Vagrant what kind of environment needs to be set up. As we don’t want to download and install an operating system for our development environment on the guest machine, we are going to use some kind of base image called box in Vagrant. Vagrant Cloud offers a large variety of boxes from different vendors, and with different operating systems and software stacks installed. As mentioned above, we are going to have a basic Ubuntu installation which is why we choose ubuntu/trusty64 . To tell Vagrant which box to use, we have to open the Vagrantfile and modify the following line:

Note: We could have achieved this by running $ vagrant init ubuntu/trusty64 instead in the first place.

To boot and ssh into our virtual development machine, run the following two commands:

After a successful ssh connection, we end up in the Ubuntu shell in the home directory of the user vagrant . Vagrant automatically synchronizes directories between your host and the guest machine. By default, only the directory containing our Vagrantfile will be kept in sync. It is mounted under /vagrant in Ubuntu. Run the following commands on the guest to create an empty file in the synchronized folder:

This should list the newly created file, but also our Vagrantfile. The file testfile.txt should be present also in our hosts filesystem.

Shutdown

Run logout to close our ssh connection with the guest OS, and shut down the guest machine gracefully using

or

depending on whether we want to just suspend it into RAM, shut the VM down or completely destroy the VM including it’s disk and all of its contents. For more information about this topic, you might want to have a look at the corresponding Vagrant documentation article.

At this point, we got a fully working guest machine running Ubuntu Server 14.04 LTS (Trusty Tahr) with file system synchronization.

You might want to move on to Vagrant – Provisioning and take a look on provisioning a virtual machine using Vagrant.

One thought on “Vagrant – First steps

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.