Setting up a dev. environment with Vagrant

Maybe you know that situation. You work in a company with a big software development department and you have high fluctuation. Every couple weeks a new intern is starting. Every couple months a new employee or freelancer is starting and you always have the problem of on boarding. They all need a development environment to get started. And in the best case all dev. environments should be identical. You want to ensure that everybody is working with the exact same version of MongoDB, Java, Ruby, PHP, Eclipse, NetBeans and whatever.

In some companies this on boarding and the whole process of setting up a new development environment takes 5 days. A whole week, until somebody can start to become productive. With Vagrant that whole ramp up time can be cut down to less than 1 hour!

In the previous blog post I described how to get started with Vagrant quickly. This blog post will describe how to use Vagrant to setup a whole development environment.

Ubuntu with XFCE4

Let’s start with the “ubuntu/trusty64” Vagrant box, which is a basic Ubuntu 14.04 LTS image. By default the GUI for a Vagrant box is disabled and the “ubuntu/trusty64” box has anyway no XServer installed. If your developers are writing C code with Vim that is all you need. Otherwise you should install an XServer and some additional graphical development tools, like a proper IDE and a Browser. I prefer XFCE4 as XServer because it is very lightweight and doesn’t require much resources. First of all we need to enable GUI in Vagrant and we should setup the RAM memory to 8 GB.

Vagrant.configure(2) do |config|
  config.vm.box = “ubuntu/trusty64”

  config.vm.provider “virtualbox” do |vb|
    vb.gui = true
    vb.memory = “8192”
  end
end

Now in the provision section we need to install XFCE4 and the VirtualBox guest utilities to enable a smooth integration into our host system.

sudo apt-get install -y xfce4 virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11

That will start XFCE4 without any icons. And because buttons without icons are not very user friendly we need some themes and icons from the Gnome project.

sudo apt-get install gnome-icon-theme-full tango-icon-theme

To be able to start XFCE4 as non privileged user we need this additional line.

sudo echo “allowed_users=anybody” > /etc/X11/Xwrapper.config

Ensure encoding

Weird thinks can happen if developers are using different encodings. That’s usually causing issues like “It works on my machine” 🙂 That’s why let’s ensure encoding!

sudo echo “LANG=en_US.UTF-8” >> /etc/environment
sudo echo “LANGUAGE=en_US.UTF-8” >> /etc/environment
sudo echo “LC_ALL=en_US.UTF-8” >> /etc/environment
sudo echo “LC_CTYPE=en_US.UTF-8” >> /etc/environment

Install Java 8

This code snippet will install the JDK 8 from Oracle. It will automatically accept the terms without asking you.

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y upgrade
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer

Install Eclipse

If you work with Java you probably want to install Eclipse. It is still the most used Java IDE on earth.

sudo wget -O /opt/eclipse-java-luna-SR2-linux-gtk-x86_64.tar.gz http://ftp.fau.de/eclipse/technology/epp/downloads/release/luna/SR2/eclipse-java-luna-SR2-linux-gtk-x86_64.tar.gz
cd /opt/ && sudo tar -zxvf eclipse-java-luna-SR2-linux-gtk-x86_64.tar.gz

Vagrantfile

The complete Vagrantfile can be found in this gist.

Start Up

Usually the Vagrantfile is stored in VCS, for example in a git repository. New employees simply need to check out the Vagrantfile and run

vagrant up

Depending on the network, CPU and RAM this can take a couple minutes. On my MacBook Pro it took 15 minutes. After the setup is done we can login with

vagrant ssh

And now we can start the XServer with

startxfce4&

That will bring up the XFCE4 Desktop like here.

Screen Shot 2015-05-05 at 11.42.20

Instead of 5 days this takes less than 1 hour to provide new employees a standardised development environment.

This was just a very simple example, but I think the idea behind Vagrant is clear. It’s a great way to standardise development environments and to cut down on boarding time to minutes.

Let me know what you think. Either here in the comments or on Twitter.

16 thoughts on “Setting up a dev. environment with Vagrant

  1. Thank you for the tutorial! Could you please help with code snippet to install java 8 on RHEL VM?

  2. … and don’t make the same mistake I made… I copied and pasted directly from this page into the VagrantFile – trouble was the double quotes copied across as some kind of curly quotes, not normal ones!

Leave a comment