Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify headless or GUI from command-line

Tags:

vagrant

According to the documentation it's easy to run a Vagrant VM in GUI mode:

config.vm.provider "virtualbox" do |v|
  v.gui = true
end

However, is there a way to do this from the command-line, for example when running vagrant up? For example,

vagrant up --gui
vagrant up --headless

Different users may prefer to boot the UI or not; it doesn't seem like it should be specified in the Vagrantfile that everyone will use!

like image 711
Daniel Buckmaster Avatar asked May 29 '14 06:05

Daniel Buckmaster


1 Answers

The GUI option is provider specific (and only very few providers support it), so it doesn't feel right for a top level vagrant command to add a switch for it.

To my experience the most common use cases for GUI are:

  • Running a desktop type machine, in which case the setting makes sense in the Vagrantfile
  • Debugging a boot etc. issue, when you just want to enable it for a moment

If you anyway have a setup where it's normal to switch the GUI on and off, you can use environment variables. For example something like this in Vagrantfile:

# Returns true if `GUI` environment variable is set to a non-empty value.
# Defaults to false
def gui_enabled?
  !ENV.fetch('GUI', '').empty?
end

Vagrant.configure('2') do |config|
  config.vm.provider 'virtualbox' do |v|
    v.gui = gui_enabled?
  end
end

Then on command line on a *nix system:

GUI=1 vagrant up

And on Windows:

set GUI=1
vagrant up
like image 143
tmatilai Avatar answered Nov 13 '22 06:11

tmatilai