This post will cover the process of installing Vagrant with the libvirt provider on CentOS 7.

For reference the following software will be used in this post.

  • CentOS - 7
  • Vagrant - 2.2.4
  • Vagrant-libvirt - 0.0.45

System Prep

Before we begin, lets ensure the host is updated.

sudo yum update -y && sudo yum upgrade -y

On this host I will set the SELinux policy to permissive.

sudo setenforce permissive
sudo sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config


Install Vagrant

sudo yum install -y

Install the vagrant-libvirt dependencies

sudo yum install -y qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm rsync

Install the vagrant-libvirt plugin.

vagrant plugin install vagrant-libvirt


Start and enable the libvirtd service.

sudo systemctl start libvirtd.service
sudo systemctl enable libvirtd.service

Add your user to the libvirt group.

sudo usermod -aG libvirt $USER
Re-login to have the group applied to your user.

Set an environment variable for the default libvirt uri as qemu:///system . Without this virsh commands point to the users qemu:///session uri which does not have privileges to add/view system wide networks.

sudo tee --append /etc/environment > /dev/null << "EOF"

Source the /etc/environment file to load the config into your environment.

source /etc/environment

Create a vagrant-libvirt network using an xml file named vagrant-libvirt.xml with the below contents.

<network connections='1'>
  <forward mode='nat'>
      <port start='1024' end='65535'/>
  <bridge name='virbr1' stp='on' delay='0'/>
  <ip address='' netmask=''>
      <range start='' end=''/>

Define and start the network.

virsh net-define vagrant-libvirt.xml
virsh net-start vagrant-libvirt
virsh net-autostart vagrant-libvirt


Confirm you can build a Vagrant box.

mkdir -p ~/vagrant/centos-test && cd ~/vagrant/centos-test
vagrant init centos/7 && vagrant up

# output

Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'centos/7' version '1902.01' is up to date...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              centos-test_default
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              1
==> default:  -- Feature:           acpi
==> default:  -- Feature:           apic
==> default:  -- Feature:           pae
==> default:  -- Memory:            512M
==> default:  -- Management MAC:
==> default:  -- Loader:
==> default:  -- Nvram:
==> default:  -- Base box:          centos/7
==> default:  -- Storage pool:      default
==> default:  -- Image:             /var/lib/libvirt/images/centos-test_default.img (41G)
==> default:  -- Volume Cache:      default
==> default:  -- Kernel:
==> default:  -- Initrd:
==> default:  -- Graphics Type:     vnc
==> default:  -- Graphics Port:     -1
==> default:  -- Graphics IP:
==> default:  -- Graphics Password: Not defined
==> default:  -- Video Type:        cirrus
==> default:  -- Video VRAM:        9216
==> default:  -- Sound Type:
==> default:  -- Keymap:            en-us
==> default:  -- TPM Path:
==> default:  -- INPUT:             type=mouse, bus=ps2
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Configuring and enabling network interfaces...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /home/bradmin/vagrant/centos-test/ => /vagrant

# SUCCESS !!!!


If you followed along, Vagrant and the vagrant-libvirt plugin are now installed in your CentOS 7 host and you can successfully build Vagrant boxes.