Provision a desktop environment with vagrant

By | October 27, 2017

Provision a Desktop Environment With Vagrant

Vagrant base boxes often do not come with a desktop environment installed. Rather than hunting around to find one that does, you can use vagrant’s provisioning capabilities to add a desktop to your base box of choice.

If you are running an Ubuntu system without a desktop environment, such as Ubuntu server, you can install a desktop environment by running:

sudo apt-get install ubuntu-desktop

which will install the full Ubuntu desktop to your system.

It’s possible to do something similar with Vagrant’s provisioning functionality. Vagrant can work with external provisioning tools, but in this case we will just incorporate a shell script into a vagrant file.

To do this we can add the following to the vagrantfile:

config.vm.provision "shell",
    inline: "sudo apt-get install --no-install-recommends lubuntu-desktop -y"

To keep the virtual machine relatively light weight I have selected to install the lxde-based lubuntu-desktop. I have also used –no-install-recommends to leave out some of the larger packages that are installed by default. Note that even a lightweight ubuntu desktop is likely to take a while to install.

It is essential that we include the ‘-y’ flag to make sure the installation is approved (it’s equivalent to us typing ‘y’).

Your final vagrantfile should look something like this:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config| = "hashicorp/precise64"
  config.vm.provision "shell",
    inline: "sudo apt-get install --no-install-recommends lubuntu-desktop -y"


vagrant up 

with this vagrant file should also run the new provision script.

If you encounter problems you may need to run

vagrant provision 


vagrant up --provision

to re-run the provisioning.

You will need to tell your vagrant file that you want to provision your machine, and where to find the provisioning script.

Now when you run vagrant up, the resulting virtual machine should have a desktop environment.