# How to Install the Vagrant libvirt Provider on Ubuntu 22.04.2 LTS Desktop or Server This document describes how to install the Vagrant libvirt provider on Ubuntu 22.04.2 LTS Desktop or Server. Much of the content is based on a [blog post](https://blogs.oracle.com/linux/getting-started-with-the-vagrant-libvirt-provider-for-oracle-linux) by Philippe Vanhaesendonck of Oracle Corp. describing how to set up the Vagrant libvirt provider on Oracle Linux. All of the commands shown should be run in a terminal window or SSH session. ## Before You Start ### Verify That Your CPU Supports Hardware Virtualization KVM on Ubuntu requires a CPU that supports hardware virtualization. To verify that your CPU supports hardware virtualization, run the following command: ```bash grep -E -c '(vmx|svm)' /proc/cpuinfo ``` If this command returns a number greater than or equal to 1, then your CPU supports hardware virtualization. ### Ensure Ubuntu is Up to Date Run the following command to make sure that your system is up to date: ```bash sudo apt-get -y update && sudo apt-get -y upgrade ``` ### Enable Password-less Sudo When the Vagrant libvirt plugin starts or stops a virtual machine, it requires root priviliges to configure NFS. To avoid having to enter your password every time you start or stop a guest, it's best to enable password-less sudo for your username. To enable password-less sudo, run the following commands: ```bash sudo su -c "echo \"$(id -un) ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/$(id -un)" sudo su -c "chmod 0440 /etc/sudoers.d/$(id -un)" ``` ## Install Virtualization ### Install KVM Packages and Start libvirt Run the following commands to install the packages needed for virtualization and start the libvirt service: ```bash sudo apt-get -y install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils sudo systemctl enable --now libvirtd ``` Optionally, if you're using Ubuntu Desktop, install [virt-manager](https://virt-manager.org/) by running `sudo apt-get -y install virt-manager`. virt-manager is helpful for troubleshooting and managing virtual machines. ### Add Your Username to Virtualization Groups To run virtualization, your username must belong to the `libvirt` and `kvm` groups. To add your username to these groups, run the following commands: ```bash sudo adduser "$(id -un)" libvirt sudo adduser "$(id -un)" kvm ``` Don't worry if you see a message saying that your username is already a member of one or both of these groups. ### Log Out and Log Back In **Important:** You need to log out of your session and log back in before the virtualization group privileges are effective. Log out and log back in before proceeding. ### Verify Virtualization Installation Verify that virtualization was installed successfully by running the following command: ```bash virsh list --all ``` The output should look like the following: ```plaintext Id Name State -------------------- ``` If you see an error message instead, something went wrong. Try re-running the commands above. If that doesn't resolve the error, try rebooting your computer. For further troubleshooting, see [KVM/Installation](https://help.ubuntu.com/community/KVM/Installation) in the Ubuntu documentation. ## Install Vagrant It's best to install Vagrant from the upstream site, rather than using the Ubuntu package, which may be outdated. To install Vagrant and enable automatic updates when new versions are released, run the commands below (from [Vagrant's website](https://developer.hashicorp.com/vagrant/downloads)): ```bash wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [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 ``` Verify that Vagrant was installed successfully by running the following command: ```bash vagrant --version ``` The output should look similar to the following, although the version may be different: ```plaintext Vagrant 2.3.7 ``` ## Install the Vagrant libvirt Plugin ### Enable "universe" Source Code Repositories Some of the prerequisites for the Vagrant libvirt plugin are in Ubuntu's "universe" source code repositories. By default, the source code repositories are disabled (commented out) in `/etc/apt/sources.list`. To enable the source code repositories, run the following commands: ```bash sudo cp /etc/apt/sources.list /etc/apt/sources.list."$(date +"%F")" sudo sed -i -e '/^# deb-src.*universe$/s/# //g' /etc/apt/sources.list sudo apt-get -y update ``` ### Install Prerequisites Needed by the Plugin Run the following commands to install and enable the prerequisites needed by the Vagrant libvirt plugin: ```bash sudo apt-get -y install nfs-kernel-server sudo systemctl enable --now nfs-server sudo apt-get -y build-dep vagrant ruby-libvirt sudo apt-get -y install ebtables dnsmasq-base sudo apt-get -y install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev ``` ### Install the Plugin Run the following command to install the Vagrant libvirt plugin: ```bash vagrant plugin install vagrant-libvirt ``` ## Done Your Ubuntu 22.04.2 LTS Desktop or Server machine is now set up to use the Vagrant libvirt provider. You can find Vagrant boxes that support the libvirt provider in [Vagrant's public box catalog](https://vagrantcloud.com/boxes/search). Oracle provides Vagrant boxes for Oracle Linux 7, 8 and 9 with libvirt provider support at [https://yum.oracle.com/boxes/](https://yum.oracle.com/boxes/). Oracle also has a [GitHub repository](https://github.com/oracle/vagrant-projects) with example Vagrant projects that provision Oracle products including Oracle Database. Enjoy!