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
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
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
The complete Vagrantfile can be found in this gist.
Usually the Vagrantfile is stored in VCS, for example in a git repository. New employees simply need to check out the Vagrantfile and run
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
And now we can start the XServer with
That will bring up the XFCE4 Desktop like here.
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”
Nice tutorial thanks for this! One question, what is the password in the gui session e.g. for logout with ubuntu user? (vagrant is not working)
If your base image is Ubuntu, the default password should be ubuntu as well.
The tutorial could be a little more actual: according to https://help.ubuntu.com/community/Locale, /etc/environment file is outdated and replaced by /etc/default/locale
Thank you for the tutorial! Could you please help with code snippet to install java 8 on RHEL VM?
Sorry but I’m not very experienced with RHEL and I don’t have time for that 😉
thank you very much, I was looking for something similar.
I’ve only one note, in my try I had to run `startx&` instead of `startxfce4&` to start XServer
Nice concise writeup. To get the GUI to start, I had to run
instead of just
p.s. Any hints on integrating startxfce4& into the VagrantFile
… 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!