How To Install and Use Vagrant for KVM Automation

Vagrant is one of the developer tools when working with KVM. It enables developers and system administrators to quickly build and manage virtual machine environments in a single workflow. It focuses on automation to lower the time required to bring up your development environment, while ensuring it’s portable, reproducible and disposable.

Vagrant by default support VirtualBox, Hyper-V, and Docker. However, alternative providers can be installed to support other virtualization platforms such as KVM and VMware.

In this section we discuss how you can utilize existing KVM hypervisor to run vagrant boxes and have isolated virtualized environments. But before another provider can be used, it must be installed. These vagtant providers are installed via the Vagrant plugin system.

To have a working vagrant setup with libvirt, the vagrant-libvirt has to be installed configured. Of course Vagrant is the main dependency that we must install before the plugin.

Installation of Vagrant

Vagrant has to be installed as the first dependency. This can be done from an upstream repository or from official binary files.

Install vagrant from repositories

  • Install on Debian / Ubuntu:
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vagrant
vagrant --version
  • Install on RHEL / Rocky / AlmaLinux / CentOS:
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
vagrant --version
  • Install on Fedora:
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager addrepo --from-repofile=https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
sudo dnf -y install vagrant
vagrant --version
  • Install on Amazon Linux:
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install vagrant
vagrant --version
  • Install on SUSE / openSUSE:
VER=$(curl -s https://api.github.com/repos/hashicorp/vagrant/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/v//')
wget https://releases.hashicorp.com/vagrant/${VER}/vagrant-${VER}-1.x86_64.rpm
sudo zypper in vagrant-${VER}-1.x86_64.rpm

To know if the installation succeeded, check the version of vagrant installed.

vagrant --version

To see all commonly used vagrant command options:

vagrant --help

To get help page on any individual command run:

vagrant <command> -h
# Example
vagrant box -h

Installation of Vagrant-libvirt plugin

Vagrant-libvirt is plugin for Vagrant that adds a Libvirt provider to Vagrant, allowing Vagrant to control and provision machines via Libvirt toolkit.

The installation of vagrant-libvirt has the following dependencies:

  • Vagrant
  • Libvirt (and QEMU) – Refer to the chapter on KVM installation
  • GCC and Make

Confirm KVM is functional in your system

systemctl status libvirtd

If not running, follow our installation chapter for a detailed how-to.

Add your user to the libvirt group:

sudo usermod -aG libvirt $(whoami)
newgrp libvirt

Install on Ubuntu / Debian

Remove distro provided vagrant-libvirt plugin if installed since it could be oldest version.

sudo apt purge vagrant-libvirt
sudo apt hold vagrant-libvirt

Next install dependencies required

sudo apt update
sudo apt install -y build-essential libvirt-daemon-system \
  ebtables libguestfs-tools ruby-fog-libvirt libvirt-dev ruby-dev

Install dependencies required, then libvirt vagrant plugin by running the following commands.

sudo gem install nokogiri
vagrant plugin install pkg-config vagrant-libvirt vagrant-mutate

Confirm the installation was successful by checking the list of installed plugins:

vagrant plugin list

Install on Rocky / AlmaLinux

Begin with the installation of dependencies:

  • Rocky / AlmaLinux / CentOS Stream 9:
sudo dnf config-manager --set-enabled crb
sudo yum -y install ruby libvirt-devel
sudo yum -y groupinstall "Development Tools"
  • Rocky / AlmaLinux 8
sudo dnf config-manager --set-enabled powertools
sudo yum -y install ruby libvirt-devel
sudo yum -y groupinstall "Development Tools"

Install libvirt vagrant plugin

sudo gem install nokogiri
vagrant plugin install pkg-config vagrant-libvirt vagrant-mutate

Confirm the installation was successful by checking the list of installed plugins:

vagrant plugin list

If your installation succeeded, there should be vagrant-libvirt in output:

pkg-config (1.5.9, global)
vagrant-libvirt (0.12.2, global)

Install on openSUSE

Get the latest stable release version number of vagrant:

VER=$(curl -s https://api.github.com/repos/hashicorp/vagrant/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/v//')

Pull the rpm package from vagrant binary downloads page.

wget https://releases.hashicorp.com/vagrant/${VER}/vagrant-${VER}-1.x86_64.rpm

Install downloaded package using zypper command line utility.

sudo zypper install --allow-unsigned-rpm --no-confirm vagrant-${VER}-1.x86_64.rpm

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

Virt-Lightning is a lightweight virtual machine management tool created to help developers and system administrators to quickly and consistently deploy […]

Virt-Lightning is a lightweight virtual machine management tool created to help developers and system administrators to quickly and consistently deploy […]

virt-customize is a powerful command-line tool used to customize virtual machine (disk image) by editing configuration files, installing packages, configuring […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.