» Basic Provider Usage

» Boxes

Vagrant boxes are all provider-specific. A box for VirtualBox is incompatiblewith the VMware Fusion provider, or any other provider. A box must be installedfor each provider, and can share the same name as other boxes as longas the providers differ. So you can have both a VirtualBox and VMware Fusion"precise64" box.

Installing boxes has not changed at all:

  1. $ vagrant box add hashicorp/precise64

Vagrant now automatically detects what provider a box is for. This isvisible when listing boxes. Vagrant puts the provider in parentheses nextto the name, as can be seen below.

  1. $ vagrant box list
  2. precise64 (virtualbox)
  3. precise64 (vmware_fusion)

» Vagrant Up

Once a provider is installed, you can use it by calling vagrant upwith the —provider flag. This will force Vagrant to use that specificprovider. No other configuration is necessary!

In normal day-to-day usage, the —provider flag is not necessarysince Vagrant can usually pick the right provider for you. More detailson how it does this is below.

  1. $ vagrant up --provider=vmware_fusion

If you specified a —provider flag, you only need to do this for theup command. Once a machine is up and running, Vagrant is able tosee what provider is backing a running machine, so commands such asdestroy, suspend, etc. do not need to be told what provider to use.

Vagrant currently restricts you to bringing up one provider per machine.If you have a multi-machine environment, you can bring up one machinebacked by VirtualBox and another backed by VMware Fusion, for example, but youcannot back the same machine with both VirtualBox andVMware Fusion. This is a limitation that will be removed in a futureversion of Vagrant.

» Default Provider

As mentioned earlier, you typically do not need to specify —providerever. Vagrant is smart enough about being able to detect the provideryou want for a given environment.

Vagrant attempts to find the default provider in the following order:

  • The —provider flag on a vagrant up is chosen above all else, if it is present.

  • If the VAGRANT_DEFAULT_PROVIDER environmental variable is set, it takes next priority and will be the provider chosen.

  • Vagrant will go through all of the config.vm.provider calls in the Vagrantfile and try each in order. It will choose the first provider that is usable. For example, if you configure Hyper-V, it will never be chosen on Mac this way. It must be both configured and usable.

  • Vagrant will go through all installed provider plugins (including the ones that come with Vagrant), and find the first plugin that reports it is usable. There is a priority system here: systems that are known better have a higher priority than systems that are worse. For example, if you have the VMware provider installed, it will always take priority over VirtualBox.

  • If Vagrant still has not found any usable providers, it will error.

Using this method, there are very few cases that Vagrant does not find thecorrect provider for you. This also allows eachVagrantfile to define what providersthe development environment is made for by ordering provider configurations.

A trick is to use config.vm.provider with no configuration at the top ofyour Vagrantfile to define the order of providers you prefer to support:

  1. Vagrant.configure("2") do |config|
  2. # ... other config up here
  3. # Prefer VMware Fusion before VirtualBox
  4. config.vm.provider "vmware_fusion"
  5. config.vm.provider "virtualbox"
  6. end