Daniel Buckmaster
Daniel Buckmaster

Reputation: 7186

Specify headless or GUI from command-line

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!

Upvotes: 16

Views: 9491

Answers (1)

tmatilai
tmatilai

Reputation: 4176

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

Upvotes: 26

Related Questions