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.

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.