Use specific Vagrant version on Fedora#
Vagrant is a tool for building and managing virtual machines locally with just a few commands and a single file. It is a good way to get started with infrastructure-as-code on your local machine. Vagrant is also shipped with Fedora to make it easier to install and use as it uses libvirt to manage the virtual machines running on Linux with kernel virtualization to provide virtual hardware. This works well until you also want to install Terraform from the Hashicorp repository and later you upgrade Vagrant to a newer version with a regular package update.
$ vagrant up The provider 'libvirt' could not be found, but was requested to back the machine 'default'. Please use a provider that exists. Vagrant knows about the following providers: docker, hyperv, virtualbox
In the example above Vagrant fails to find libvirt to connect to KVM and manage the virtual machine. Multiple providers are available for Vagrant to use, but the one that is used is not the one that is installed on the machine or can be used. This is a known issue with Vagrant on Linux and does not use the system Ruby environment with the lirbary for libvirt. Downgrading to the version of Vagrant that is shipped with Fedora will fix this issue.
$ sudo dnf info vagrant Last metadata expiration check: 2:58:01 ago on Sat Aug 13 09:43:18 2022. Installed Packages Name : vagrant Version : 2.3.0 Release : 1 Architecture : x86_64 Size : 108 M Source : vagrant-2.3.0-1.src.rpm Repository : hashicorp Summary : Vagrant is a tool for building and distributing development environments. Please submit issues to : https://github.com/hashicorp/vagrant/issues URL : https://www.vagrantup.com License : MIT Description : Vagrant is a tool for building and distributing development environments. Please submit issues to : https://github.com/hashicorp/vagrant/issues Available Packages Name : vagrant Version : 2.2.19 Release : 4.fc36 Architecture : noarch Size : 2.4 M Source : vagrant-2.2.19-4.fc36.src.rpm Repository : @System From repo : updates Summary : Build and distribute virtualized development environments URL : http://vagrantup.com License : MIT Description : Vagrant is a tool for building and distributing virtualized development : environments.
If you want to use the latest version of Vagrant on Fedora you can install it with the following command. After this Vagrant will work again with KVM on Linux.
$ sudo dnf install vagrant-2.2.19-4.fc36
Pinning the version of Vagrant#
Now that Vagrant works again the problem with libvirt is fixed, but with the next update, the problem will return as Vagrant is updated to the latest version again. DNF has a plugin called versionlock to lock to a specific version of a package and stops it from being updated.
$ sudo dnf install python3-dnf-plugin-versionlock
With the plugin installed you can lock the version of Vagrant to the latest version. This can be done with the command
dnf versionlock add vagrant and an overview with the command
dnf versionlock list confirms that the version is locked.
$ sudo dnf versionlock add vagrant Last metadata expiration check: 2:52:28 ago on Sat Aug 13 09:43:18 2022. Adding versionlock on: vagrant-0:2.2.19-4.fc36.* $ sudo dnf versionlock list Last metadata expiration check: 2:53:34 ago on Sat Aug 13 09:43:18 2022. vagrant-0:2.2.19-4.fc36.*
Running the command
vagrant up will now work again as it can find libvirt to connect to KVM and it successfully starts the virtual machine.
$ vagrant up Bringing machine 'default' up with 'libvirt' provider... ==> default: Checking if box 'fedora/36-cloud-base' version '36-20220504.1' is up to date... ==> default: Starting domain. ==> default: Waiting for domain to get an IP address... ==> default: Waiting for machine to boot. This may take a few minutes...
Setting a versionlock on Vagrant will prevent it from being updated. If you want to upgrade to the latest version of Vagrant you first have to remove the versionlock with
dnf versionlock del vagrant. This will allow Vagrant to be updated during a system upgrade for example or when you have to install a security update.
$ sudo dnf versionlock del vagrant Last metadata expiration check: 2:52:50 ago on Sat Aug 13 09:43:18 2022. Deleting versionlock for: vagrant-0:2.2.19-4.fc36.* $ sudo dnf versionlock list Last metadata expiration check: 2:53:14 ago on Sat Aug 13 09:43:18 2022.
Setting a versionlock isn’t perfect as it will prevent Vagrant from being updated when needed. As a result, you can end up with a version of Vagrant that is not the latest version or has a security vulnerability. This is a known issue with Hashicorp’s Vagrant repository and will be fixed in a future release hopefully when Vagrant 3.0 is released as then Vagrant should have been rewritten in Go. As version 2.3 has just been released and 2.4 is still in development the use of the versionlock plugin is recommended.