Install Vagrant with vagrant-libvirt

Install Vagrant and vagrant-libvirt in CentOS 8

In order to use libvirt related VMs, such includes qemu and kvm, we need to use vagrant-libvirt plugin for Vagrant. To do this, following steps shall be followed

Install Vagrant

Add repo for Vagrant and install vagrant by:

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 Libvirt

Install all dependencies for libvirt as well as libvirt's libraries

# Install dependencies for libvirt
sudo dnf install --assumeyes libvirt libguestfs-tools \
    gcc libvirt-devel libxml2-devel make pkgconf-pkg-config ruby-devel
sudo dnf install --assumeyes byacc cmake gcc-c++ rpm-build wget zlib-devel
sudo systemctl enable libvirtd 
sudo systemctl start libvirtd
sudo usermod -aG libvirt $USER 

In here, if we do not perform usermod the libvirt will not create and manage VMs. Therefore, add current user for libvirt.

Install vagrant-libvirt

In order to use vagrant-libvirt in Vagrant as the provider, use vagrant-libvirt.

Example Vagrantfile

To verify that the vagrant-libvirt was installed properly, use following Vagrantfile to check if it was installed properly:

This will create a VM with ubuntu2204 image and will perform sudo apt-get update.

Last updated