In this tutorial, we will see how to install Vagrant on Linux operating systems. Installing Vagrant is quite easy! All you have to do is to head over the Vagrant downloads page, grab the suitable precompiled binary version for your Linux distribution and install it as the way you would normally install other applications. You can also install Vagrant from the default repositories. Here I have included all possible ways to install Vagrant on your Linux box.
1. Install Vagrant On Linux
Vagrant is available in the official repositories of most Linux and Unix distributions. So we can install vagrant using the default package managers.
For instance, run the following command to install Vagrant on Debian, Ubuntu, Linux Mint:
$ sudo apt install vagrant
$ sudo dnf install vagrant
$ sudo zypper install vagrant
The official versions in the repositories might be very outdated. If you want the most recent version, go to the official Vagrant downloads page and download the latest binary file for your Linux operating systems.
For instance, if you're using Debian and other Debian-based systems such as Ubuntu, just download .deb version. As of writing this guide, the latest version was 2.2.10. It is available for both 32 bit and 64 bit architecture.
After downloading the .deb file, go to the download section and install it like below:
$ sudo apt install gdebi
$ sudo gdebi vagrant_2.2.10_x86_64.deb
Here, the reason I used "gdebi" is because it automatically installs the necessary dependencies.
If you have downloaded the .rpm file, you can install it using command:
$ sudo dnf localinstall vagrant_2.2.10_x86_64.rpm
$ sudo yum localinstall vagrant_2.2.10_x86_64.rpm
2. Install hypervisors
After installing Vagrant, you need to install any virtualization hypervisors, for example VirtualBox or KVM. Because, Vagrant is not a standalone virtualization software. It is just a wrapper and front-end for other virtualization applications.
Vagrant is originally developed for VirtualBox. Since the version 1.1, the vagrant team extended its support for other popular virtualization software and server environments including Aws, Azure, GCE, Docker, KVM, Proxmox, Openstack, Openvz, VMware and lot more. You can view the complete list of supported providers/environments here.
For the purpose of this guide, I am going to use Oracle VirtualBox. Because, installing Virtualbox is easy and Vagrant uses VirtualBox as default provider.
To install VirtualBox on Debain, Ubuntu, Linux Mint, run the following command:
$ sudo apt install virtualbox
To install Virtualbox on Red Hat, CentOS, Fedora, run:
$ sudo dnf install virtualbox
To install Virtualbox on SUSE/openSUSE, run:
$ sudo zypper install virtualbox
If you prefer to use KVM, you can follow the below guides to install it.
- Install And Configure KVM In CentOS 8 Server
- Install And Configure KVM In Ubuntu 20.04 Headless Server
- Install And Configure KVM In OpenSUSE Tumbleweed
3. Verify Vagrant installation
To verify if Vagrant is properly installed, simply run it without any options from the terminal:
It will return the Vagrant help section.
Usage: vagrant [options] <command> [<args>] -h, --help Print this help. Common commands: box manages boxes: installation, removal, etc. cloud manages everything related to Vagrant Cloud destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment upload upload to machine via communicator validate validates the Vagrantfile version prints current and latest Vagrant version winrm executes commands on a machine via WinRM winrm-config outputs WinRM configuration to connect to the machine For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`. --[no-]color Enable or disable color output --machine-readable Enable machine readable output -v, --version Display Vagrant version --debug Enable debug output --timestamp Enable timestamps on log output --debug-timestamp Enable debug output with timestamps --no-tty Enable non-interactive output
You can also -h or --help parameter to bring up the help section.
$ vagrant --help [Or] $ vagrant -h
To get help for individual commands, run:
$ vagrant <COMMAND-NAME> -h
To view Vagrant version, run:
$ vagrant version
It will return the currently installed version and latest available version.
Installed Version: 2.2.10 Latest Version: 2.2.10 You're running an up-to-date version of Vagrant!
$ vagrant -v
4. Upgrade Vagrant
If you have installed Vagrant from official repositories using distribution's package manager, you can simply upgrade Vagrant to newer version by updating your system. For instance, on Debian-based systems, the following commands will update Vagrant to newer version:
$ sudo apt update
$ sudo apt upgrade
On RPM-based systems, such as RHEL, CentOS, do:
$ sudo yum update
$ sudo dnf update
$ sudo zypper update
If you have manually downloaded and installed the Vagrant, just download the new version from official Vagrant download page and install it as described in the "Install Vagrant" section above.
The new installers will properly overwrite and remove old files. It is recommended that no other Vagrant processes are running during the upgrade process.
5. Vagrant Troubleshooting
If you run multiple hypervisors on the same host machine, you will probably be encountered with an error something like below when starting a VM:
There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Command: ["startvm", <ID of the VM>, "--type", "headless"] Stderr: VBoxManage: error: VT-x is being used by another hypervisor (VERR_VMX_IN_VMX_ROOT_MODE). VBoxManage: error: VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_VMX_IN_VMX_ROOT_MODE) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole
This error occurs because an another hypervisor, for example KVM, is currently in use. To fix this error, you may need to temporarily blocklist that hypervisor.
Find the KVM module using command:
$ lsmod | grep kvm
If you host system is Intel, you will get the following output:
kvm_intel 282624 0 kvm 663552 1 kvm_intel
If it is AMD, you will get this instead:
kvm_intel 282624 0 kvm 663552 1 kvm_amd
Now block the KVM module using command:
$ echo 'blacklist kvm-intel' >> /etc/modprobe.d/blacklist.conf
Type "kvm-amd" in the above command if your CPU is AMD.
Restart your system and then try again running Vagrant. This time VM will start without any issues.
That's it. We have successfully installed Vagrant on Linux. Check the following article to learn how to use Vagrant to setup a virtualized environment and how to create and manage the virtual machines using Vagrant.