Vagrant – Enabling a CentOS VM’s gui mode

Most vagrant boxes comes without the gui desktop interface. This tutorial will show you how install and access to that gui interface. Let’s use the standard CentOS 7 vm:

$ vagrant init centos/7

The above command will create a Vagrantfile.

Next open up the vagrant file and ensure the following virtualbox setting section exists:

config.vm.provider "virtualbox" do |v|
  v.gui = true
  v.memory = 2048
  v.cpus = 2

Log into your vm:

$ vagrant ssh

Then switch to root:

$ sudo -i 

Then install the gui desktop collection of packages:

$ yum groupinstall -y 'gnome desktop'
$ yum install -y 'xorg*'

Next uninstall the following packages:

yum remove -y initial-setup initial-setup-gui

These packages are to do with agreeing to EULA agreements, which means it requires user interaction, which can prevent automated startups via vagrant.

Next switch to the gui target:

$ systemctl isolate
$ systemctl set-default   # to make this persistant

You should now see the gui desktop in your virtualbox window. If not, then try restarting the box:

$ vagrant halt ; vagrant up

I’ve also created the vagrant enable gui shell script that you can copy into your vagrant projects.