How to Install Vagrant in Linux

This series is focused on Vagrant with VirtualBox as the Provider. From the previous article, you might have an understanding of what is a provider. Virtualbox is the default provider with Vagrant and it is cross-platform and can run in Windows, Linux, and macOS. So before installing Vagrant you should set up Virtualbox in your machine.

Take a look at our installation guide on how to set up virtualbox. Once you are done setting up Virtualbox, it’s time to download vagrant binaries and install them. There are two ways you can install Vagrant in Linux. One is by downloading the repo file directly from the official site and installing it locally and secondly by using package managers.

We will see how to use both methods.

Install Vagrant in Linux

Installing Vagrant using a package manager is simple. Depending upon the distribution you are using, repositories can be added and vagrant can be installed by running the following command in your machine.

Install Vagrant on Fedora

$ sudo dnf install -y dnf-plugins-core
$ sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
$ sudo dnf -y install vagrant

Install Vagrant on Centos/RHEL

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
$ sudo yum -y install vagrant

Install Vagrant on Debian/Ubuntu

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
$ sudo apt-get update && sudo apt-get install vagrant

Install Vagrant on Amazon Linux

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
$ sudo yum -y install vagrant

Alternatively, you can download the Vagrant repo files from the official site based upon the distribution you are running. Once you have downloaded the repo file you have to run local install. Go to the directory where you have downloaded the repo file and run the following command according to your distribution.

$ sudo rpm -ivh vagrant_2.2.16_x86_64.rpm      # RHEL based distribution
$ sudo dpkg -i vagrant_2.2.16_x86_64.deb       # Debian/Ubuntu-based distribution
$ sudo pacman -U vagrant_2.2.16_x86_64.tar.zst # Arch based distribution

To check if Vagrant installation is successful you can run the following command which will check for the vagrant version.

$ vagrant --version

Vagrant 2.2.16

Uninstall Vagrant in Linux

Removing Vagrant is simple. If you have installed via package manager then run the following command to remove the installed packages.

$ sudo apt remove vagrant  ⇐ Debian/Ubuntu-based distribution
$ sudo yum remove vagrant  ⇐ Centos/RHEL distribution
$ sudo dnf remove vagrant  ⇐ Fedora distribution

If you have downloaded the repo file and installed it locally, then you have to remove the following directories.

# sudo rm -rf /opt/vagrant
# sudo rm -f /usr/bin/vagrant

NOTE: It will remove the vagrant installation directories alone, not the project directories you will be working on.

In the next article, we will be taking a look at how to set up our first Vagrant box and how to work with the vagrant file.

Got something to say? Join the discussion.