Debian

Set Default Vagrant Provider to VirtualBox or Libvirt

Vagrant supports multiple virtualization providers – VirtualBox, libvirt (KVM), VMware, Hyper-V, Docker, and others. By default, Vagrant tries VirtualBox when you run vagrant up. If you use a different provider as your daily driver, typing --provider libvirt every time gets old fast. This guide covers every way to set a default provider in current Vagrant versions so the right backend is picked automatically.

How Vagrant Selects a Provider

Vagrant uses the following priority order when deciding which provider to use for vagrant up:

  1. The --provider flag passed on the command line
  2. The VAGRANT_DEFAULT_PROVIDER environment variable
  3. Provider configuration in the Vagrantfile
  4. The order in which providers are detected on the system (VirtualBox wins if installed)

Understanding this order matters. A command-line flag always wins, followed by the environment variable, then the Vagrantfile setting.

Method 1 – VAGRANT_DEFAULT_PROVIDER Environment Variable

This is the most common and portable approach. Set the variable in your shell profile so it applies to every Vagrant project on the machine.

For Bash, add to ~/.bashrc:

echo 'export VAGRANT_DEFAULT_PROVIDER=libvirt' >> ~/.bashrc
source ~/.bashrc

For Zsh, add to ~/.zshrc:

echo 'export VAGRANT_DEFAULT_PROVIDER=libvirt' >> ~/.zshrc
source ~/.zshrc

For Fish shell:

set -Ux VAGRANT_DEFAULT_PROVIDER libvirt

Replace libvirt with whichever provider you prefer – virtualbox, vmware_desktop, docker, or hyperv.

Verify the variable is active:

echo $VAGRANT_DEFAULT_PROVIDER

Now running vagrant up without any flags uses your chosen provider.

Method 2 – Set the Provider in the Vagrantfile

If a specific project should always use a particular provider regardless of what is set globally, declare it inside the Vagrantfile. This approach is good for team projects where everyone needs the same backend.

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2404"

  config.vm.provider "libvirt" do |lv|
    lv.memory = 2048
    lv.cpus = 2
  end
end

When a Vagrantfile defines provider-specific configuration blocks, Vagrant prefers the first provider block it encounters if no other override is set. To make the preference explicit, you can use the config.vm.provider ordering or rely on the environment variable to complement it.

Method 3 – Support Multiple Providers in One Vagrantfile

Real-world teams often have members on different platforms – someone runs libvirt on Linux, another uses VirtualBox on macOS. You can define multiple provider blocks in the same Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2404"

  config.vm.provider "libvirt" do |lv|
    lv.memory = 2048
    lv.cpus = 2
    lv.driver = "kvm"
  end

  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
    vb.cpus = 2
    vb.gui = false
  end

  config.vm.provider "vmware_desktop" do |vmw|
    vmw.vmx["memsize"] = "2048"
    vmw.vmx["numvcpus"] = "2"
  end

  config.vm.provider "docker" do |d|
    d.image = "ubuntu:24.04"
    d.has_ssh = true
  end
end

Each team member sets their own VAGRANT_DEFAULT_PROVIDER environment variable, and the Vagrantfile handles all of them.

Method 4 – Per-Command Override

You can always override any default on a single command by passing the --provider flag:

vagrant up --provider=virtualbox
vagrant up --provider=libvirt
vagrant up --provider=docker

This takes the highest priority and ignores both the environment variable and Vagrantfile defaults.

Checking Which Provider a VM is Using

After a VM is created, Vagrant locks it to the provider that was used during the first vagrant up. To see which provider an existing VM uses:

vagrant status

The output includes the provider name in parentheses:

default                   running (libvirt)

If you want to switch an existing VM to a different provider, you need to destroy it and recreate it:

vagrant destroy -f
vagrant up --provider=virtualbox

Common Provider Names Reference

ProviderValue for VAGRANT_DEFAULT_PROVIDERPlugin Required
VirtualBoxvirtualboxNo (built-in)
libvirt (KVM)libvirtYes: vagrant-libvirt
VMware Desktopvmware_desktopYes: vagrant-vmware-desktop
Hyper-VhypervNo (built-in, Windows only)
DockerdockerNo (built-in)

Install the libvirt plugin if needed:

vagrant plugin install vagrant-libvirt

Troubleshooting

Vagrant ignores my VAGRANT_DEFAULT_PROVIDER setting – Make sure you exported the variable (not just assigned it). Run env | grep VAGRANT to confirm it is in your environment.

Box not available for this provider – Not all Vagrant boxes support every provider. Check the box page on Vagrant Cloud for available provider builds. The generic/* boxes from Roboxes support VirtualBox, libvirt, VMware, and Hyper-V.

Provider plugin not found – Run vagrant plugin list to see installed plugins. Install missing ones with vagrant plugin install <name>.

Wrapping Up

Setting a default Vagrant provider saves keystrokes and reduces errors in your daily workflow. The VAGRANT_DEFAULT_PROVIDER environment variable is the cleanest global approach. For per-project control, define provider blocks in the Vagrantfile. For teams with mixed platforms, combine both approaches – multiple provider blocks in the Vagrantfile and each developer sets their own environment variable.

Related Articles

Containers Install Kubernetes Cluster on Ubuntu 22.04 using kubeadm Fedora Install Deepin Desktop Environment on Fedora 29 / Fedora 28 Openstack OpenStack Deployment on Ubuntu 22.04/20.04/18.04 using DevStack Debian Install VirtualBox on Ubuntu 24.04 / Debian 13 / Kali Linux

Press ESC to close