Vagrant – Provisioning

In the first part of this tutorial series, we set up a fully working vagrant environment with Ubuntu running on our guest machine.

As we used an existing box from Vagrant Cloud, we now going to figure out possibilities how to adapt this default machine according to our needs. In this post, how to install additional software using the Ubuntu package manager.

The most easy way to adapt our virtual machine according to our needs, is to simply run commands from the Ubuntu shell. In this post, we want to install the GNU Compiler Collection which can be done by  $ sudo apt-get install build-essential . We could now just ssh into our guest and install the package by hand, but that would require us to repeat this step every time we choose to destroy our virtual machine using $ vagrant destroy or move on to another host. Luckily, there is a way to have Vagrant doing this for us when initializing a new virtual environment. By adding the following lines to our existing Vagrantfile, we tell Vagrant to use a basic shell for provisioning. We can even specify a relative path to a bash script.

The file , located right next to our Vagrantfile, is now being used to provision our guest machine. Now we create that file with the following content:

This will make sure that our development environment always has this package installed.

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.


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 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.


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


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.