Install Vagrant with KVM Provider on CentOS 8 - CentLinux


Saturday, 9 May 2020

Install Vagrant with KVM Provider on CentOS 8

Install Vagrant with Libvirt on CentOS 8

In this article, you will learn how to install Vagrant with KVM Provider on CentOS 8 server. We will also show you how to create a virtual machine by using Vagrant boxes and KVM provider.

This Article Provides:


What is Vagrant? :

Vagrant is a free and open source software for easy provisioning and orchestration of virtual software development environments. This virtual environment is called Vagrant Box and it is portable, so it can be used over many platforms without any change. Vagrant is developed by HashiCorp and distributed under MIT License.

Vagrant uses a declarative configuration file called Vagrantfile, that describes all the software requirements, packages, operating system configurations, users and more.

Vagrant was originally tied with Oracle VirtualBox. But later Vagrant added the support for other virtualization platforms such as VMWare and KVM.

In technical terminology, these virtualization platforms (VirtualBox, KVM, VMWare, etc) are called Providers, while the Vagrant itself is termed as Provisioner.


What is KVM:

KVM (Kernel based Virtual Machine) is a virtualization module in Linux kernel, that allows Kernel to function as a Hypervisor. In CentOS 7 or later, KVM has replaced legacy Xen Kernel, and now the KVM is used in most of the Linux distros for virtualization.

KVM is free and open source and we can use it to configure a high performace and feature enrich CentOS virtualization server.


Environment Specification:

We are provisioned a CentOS 8 Server with following specifications.

  • CPU - 3.4 Ghz (4 cores)
  • Memory - 8 GB
  • Storage - 80 GB
  • Operating System - CentOS 8.1
  • Hostname –
  • IP Address - /24


Update Software Packages in CentOS 8:

Connect with as root user by using PuTTY.

We are updating installed software packages in our CentOS 8 server by using dnf command.

[root@vagrant-02 ~]# dnf update -y ... Installed: kernel-4.18.0-147.8.1.el8_1.x86_64 kernel-core-4.18.0-147.8.1.el8_1.x86_64 kernel-modules-4.18.0-147.8.1.el8_1.x86_64 Removed: kernel-4.18.0-80.el8.x86_64 kernel-core-4.18.0-80.el8.x86_64 kernel-modules-4.18.0-80.el8.x86_64 Complete!


Install Libvirt and KVM/QEMU on CentOS 8:

Since, we are planning to use Vagrant with KVM provider, therefore, we need to install libvirt and KVM/QEMU packages on our CentOS 8 server.

[root@vagrant-02 ~]# dnf install -y @virt virt-install ... psmisc-23.1-3.el8.x86_64 python3-chardet-3.0.4-7.el8.noarch python3-pysocks-1.6.8-3.el8.noarch python3-requests-2.20.0-2.1.el8_1.noarch python3-urllib3-1.24.2-2.el8.noarch quota-1:4.04-10.el8.x86_64 quota-nls-1:4.04-10.el8.noarch rdma-core-22.3-1.el8.x86_64 rpcbind-1.2.5-4.el8.x86_64 syslinux-6.04-4.el8.x86_64 syslinux-extlinux-6.04-4.el8.x86_64 syslinux-extlinux-nonlinux-6.04-4.el8.noarch syslinux-nonlinux-6.04-4.el8.noarch systemd-container-239-18.el8_1.5.x86_64 userspace-rcu-0.10.1-2.el8.x86_64 xml-common-0.6.3-50.el8.noarch Complete!

Here, we have installed libvirt and KVM/QEMU on CentOS 8 but for a detailed step by step guide you can refer to our previous article: Install KVM based CentOS Virtualization Server.


Install Ruby on CentOS 8:

Vagrant is written in Ruby and it requires Ruby development tools for compilation of Vagrant extensions and plugins. Thus, we are required to install Ruby on CentOS 8 before installing Vagrant.

Ruby 2.5.5 is available in AppStream yum repository and we can install it using dnf command.

[root@vagrant-02 ~]# dnf install -y ruby ruby-devel ... Installed: ruby-2.5.5-105.module_el8.1.0+214+9be47fd7.x86_64 ruby-devel-2.5.5-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-bigdecimal-1.3.4-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-did_you_mean-1.2.0-105.module_el8.1.0+214+9be47fd7.noarch rubygem-io-console-0.4.6-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-rdoc-6.0.1-105.module_el8.1.0+214+9be47fd7.noarch ruby-irb-2.5.5-105.module_el8.1.0+214+9be47fd7.noarch ruby-libs-2.5.5-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-json-2.1.0-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-openssl-2.1.2-105.module_el8.1.0+214+9be47fd7.x86_64 rubygem-psych-3.0.2-105.module_el8.1.0+214+9be47fd7.x86_64 rubygems- Complete!

Check version of installed ruby command.

[root@vagrant-02 ~]# ruby -v ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]


Install Nokogiri on CentOS 8:

Ruby requires Nokogiri library for parsing HTML and XML while compliling Vagrant extensions.

We can either install nokogiri from EPEL (Extra Packages for Enterprise Linux) or by using RubyGem package manager.

Since, we have RubyGem package manager already installed with installation of Ruby, therefore, we can use it to install nokogiri gem.

But first we have to install the nokogiri dependencies as follows.

[root@vagrant-02 ~]# dnf install -y make gcc rpm-build ruby-devel zlib-devel ... Installed: gcc-8.3.1-4.5.el8.x86_64 rpm-build-4.14.2-26.el8_1.x86_64 make-1:4.2.1-9.el8.x86_64 zlib-devel-1.2.11-10.el8.x86_64 annobin-8.78-1.el8.x86_64 cpp-8.3.1-4.5.el8.x86_64 dwz-0.12-9.el8.x86_64 efi-srpm-macros-3-2.el8.noarch gc-7.6.4-3.el8.x86_64 gdb-headless-8.2-6.el8.x86_64 ghc-srpm-macros-1.4.2-7.el8.noarch go-srpm-macros-2-16.el8.noarch guile-5:2.0.14-7.el8.x86_64 isl-0.16.1-6.el8.x86_64 libatomic_ops-7.6.2-3.el8.x86_64 libbabeltrace-1.5.4-2.el8.x86_64 libipt-1.6.1-8.el8.x86_64 libmpc-1.0.2-9.el8.x86_64 ocaml-srpm-macros-5-4.el8.noarch openblas-srpm-macros-2-2.el8.noarch perl-srpm-macros-1-25.el8.noarch python-srpm-macros-3-37.el8.noarch python3-rpm-macros-3-37.el8.noarch qt5-srpm-macros-5.11.1-2.el8.noarch redhat-rpm-config-120-1.el8.noarch rust-srpm-macros-5-2.el8.noarch elfutils-0.176-5.el8.x86_64 glibc-devel-2.28-72.el8_1.1.x86_64 glibc-headers-2.28-72.el8_1.1.x86_64 kernel-headers-4.18.0-147.8.1.el8_1.x86_64 libxcrypt-devel-4.1.1-4.el8.x86_64 patch-2.7.6-9.el8_0.x86_64 unzip-6.0-41.el8.x86_64 zip-3.0-23.el8.x86_64 Complete!

Now, install nokogiri library using gem command.

[root@vagrant-02 ~]# gem install nokogiri Fetching: mini_portile2-2.4.0.gem (100%) Successfully installed mini_portile2-2.4.0 Fetching: nokogiri-1.10.9.gem (100%) Building native extensions. This could take a while... Successfully installed nokogiri-1.10.9 2 gems installed


Install Vagrant on CentOS 8:

At the time of this writeup, latest stable version is Vagrant 2.2.9. You can download Vagrant 2.2.9 for your respective operating system from Vagrant website.


Copy the URL of your required Vagrant RPM and use wget command to download it.

[root@vagrant-02 ~]# wget --2020-05-08 15:40:41-- Resolving (, 2a04:4e42:39::439 Connecting to (||:443... connected. HTTP request sent, awaiting response... 200 OK Length: 43598220 (42M) [application/x-redhat-package-manager] Saving to: âvagrant_2.2.9_x86_64.rpmâ vagrant_2.2.9_x86_6 100%[===================>] 41.58M 937KB/s in 48s 2020-05-08 15:41:30 (890 KB/s) - âvagrant_2.2.9_x86_64.rpmâ saved [43598220/43598220]

Install Vagrant RPM on CentOS 8 by using dnf command.

[root@vagrant-02 ~]# dnf install -y vagrant_2.2.9_x86_64.rpm Last metadata expiration check: 0:00:07 ago on Fri 08 May 2020 03:52:57 PM PKT. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: vagrant x86_64 1:2.2.9-1 @commandline 42 M Transaction Summary ================================================================================ Install 1 Package Total size: 42 M Installed size: 122 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : vagrant-1:2.2.9-1.x86_64 1/1 Verifying : vagrant-1:2.2.9-1.x86_64 1/1 Installed: vagrant-1:2.2.9-1.x86_64 Complete!

Check version of installed vagrant command.

[root@vagrant-02 ~]# vagrant --version Vagrant 2.2.9

Vagrant has been installed on CentOS 8 server.


Install Vagrant plugin for KVM Provider:

We need to install a Vagrant plugin to use KVM provider.

libvirt-devel package is required for vagrant-libvirt plugin installation, and we are installing it by using dnf command.

[root@vagrant-02 ~]# dnf install –y libvirt-devel ... Installed: libvirt-devel-4.5.0-35.3.module_el8.1.0+297+df420408.x86_64 Complete!

Now, install vagrant-libvirt plugin as follows.

[root@vagrant-02 ~]# vagrant plugin install vagrant-libvirt Installing the 'vagrant-libvirt' plugin. This can take a few minutes... Building native extensions. This could take a while... Building native extensions. This could take a while... Fetching fog-libvirt-0.7.0.gem Fetching vagrant-libvirt-0.0.45.gem Installed the plugin 'vagrant-libvirt (0.0.45)'!

We have successfully installed Vagrant with KVM on CentOS 8.


Use Vagrant Boxes to create a KVM Virtual Machine:

Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment.

You can search for your required boxes at Vagrant Cloud.


We are downloading the centos/7 box by using vagrant command.

[root@vagrant-02 ~]# vagrant box add centos/7 --provider=libvirt ==> box: Loading metadata for box 'centos/7' box: URL: ==> box: Adding box 'centos/7' (v1905.1) for provider: libvirt box: Downloading: ==> box: Box download is resuming from prior download progress Download redirected to host: ==> box: Successfully added box 'centos/7' (v1905.1) for 'libvirt'!

Vagrant also needs rsync utility, so install it using dnf command.

[root@vagrant-02 centos7]# dnf install -y rsync ... Installed: rsync-3.1.3-6.el8.x86_64 Complete!

Create a project directory for our CentOS 7 virtual machine.

[root@vagrant-02 ~]# mkdir centos7 [root@vagrant-02 ~]# cd centos7

Use vagrant command to initialize our CentOS 7 project. This command will create a Vagrantfile in our project directory, that can be used to create the desired virtual machine. You can customize this Vagrantfile according to your requirements.

[root@vagrant-02 centos7]# vagrant init centos/7 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `` for more information on using Vagrant.

Create and start CentOS 7 virtual machine as follows.

[root@vagrant-02 centos7]# vagrant up Bringing machine 'default' up with 'libvirt' provider... ==> default: Checking if box 'centos/7' version '1905.1' is up to date... ==> default: Creating image (snapshot of base box volume). ==> default: Creating domain with the following settings... ==> default: -- Name: centos7_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/centos7_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: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: 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: /root/centos7/ => /vagrant

To check status of our CentOS 7 virtual machine.

[root@vagrant-02 centos7]# virsh list Id Name State ---------------------------------------------------- 2 centos7_default running

We have successfully created our first virtual machine by using Vagrant boxes and KVM provider.

In this article, you have learned how to install Vagrant with KVM Provider on CentOS 8. If you planning to implement Vagrant in your environment then we strongly recommend you to read Hands-On DevOps with Vagrant by Packt Publishing or enroll yourself or your team in Fundamentals of Vagrant course by Udemy.

1 comment: