Install Vagrant on Rocky Linux 8: Best VM Build Tool
In this guide from Orcacore, you will learn how to Install Vagrant on Rocky Linux 8. Vagrant is a powerful tool for building and managing virtual machine environments within a unified workflow. Focusing on automation, Vagrant provides a user-friendly command-line interface for environment management and acts as an interpreter for text-based environment definitions known as Vagrantfiles. The use of Vagrant significantly reduces development environment setup time and enhances parity with production environments. Install Vagrant on Rocky Linux 8 and streamlining your workflow.
To follow this guide, you need to log in to your Rocky Linux 8 server as a non-root user with sudo privileges. Instructions for setting this up can be found in our article about the Initial Server Setup with Rocky Linux 8.
Additionally, you need VirtualBox installed on your server. You can find instructions for this in our article on How To Install VirtualBox on Rocky Linux 8.
1. Vagrant Setup on Rocky Linux 8
To begin the Install Vagrant on Rocky Linux 8 process, you first need to install the yum-utils
package:
sudo dnf install -y yum-utils
Add Vagrant Repository
Next, add the official Vagrant repository to your Rocky Linux 8 system using the following command:
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
Install Vagrant
Now, install the latest version of Vagrant with this command:
sudo dnf -y install vagrant
To verify the installation, check the Vagrant version:
vagrant --version
You should see output similar to this:
**Output**
Vagrant 2.3.4
You have now successfully completed the Install Vagrant on Rocky Linux 8 process. Let’s move on to how to use Vagrant.
2. How To Use Vagrant?
Now, let’s demonstrate how to use Vagrant by creating a sample development environment.
First, create a directory to store your Vagrant project file:
mkdir ~/vagrant-project
Then, initialize a new Vagrantfile, specifying the "box" you want to use. Boxes are the package format for Vagrant environments and are provider-specific.
You can find a list of available Vagrant boxes on the Vagrant Catalog page.
In this example, we will use ubuntu/trusty64
.
Navigate to your Vagrant project directory:
cd ~/vagrant-project
Now, initialize the Vagrantfile:
vagrant init ubuntu/trusty64
You will see output similar to this:
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` for your first virtual environment! Please read
the `Vagrantfile` in order to learn more about the parameters that
can be configured.
You can open the Vagrantfile with your favorite text editor and modify it to suit your specific needs.
Run the following command to create and configure the virtual machine as defined in the Vagrantfile:
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' version '20200114.0.0' is up to date...
==> default: Setting the name of the VM: vagrant-project_default_1683803281748_28992
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in the box...
default: The box 'ubuntu/trusty64' does not have the VirtualBox Guest Additions properly installed. If you are using a box
default: made by someone else, you might want to notify them that these additions are not properly built in.
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
default: /vagrant => /home/user/vagrant-project
Vagrant automatically mounts the project directory at /vagrant
within the virtual machine. This allows you to seamlessly work on your project files from your host machine.
You can SSH into your virtual machine using:
vagrant ssh
To stop the virtual machine:
vagrant halt
To completely stop and remove all resources created during the machine’s creation:
vagrant destroy
Conclusion
Vagrant is a valuable open-source tool for building, managing, and maintaining virtual machine environments in a consistent and efficient manner. You have now learned how to Install Vagrant on Rocky Linux 8 and how to use it for basic VM management.
Enjoy using Vagrant! Please follow us on Facebook and Twitter.
You may also be interested in these articles:
Caddy Web Server Setup Rocky Linux 8
aaPanl: Easy Control Panel For Rocky Linux 8
Xfce Desktop Environment Rocky Linux 8
Varnish Cache With Apache Rocky Linux 8
Cockpit Administration Tool Rocky Linux 8
Alternative Solutions for Virtual Machine Management on Rocky Linux 8
While Vagrant is a fantastic tool for managing virtual machines, other viable alternatives exist. Here are two different approaches to achieving similar results on Rocky Linux 8:
1. Using Podman with a Containerfile
Instead of relying on full-fledged virtual machines, you can leverage containerization with Podman. Podman offers a daemon-less container engine that seamlessly integrates with systemd, making it a lightweight and secure alternative to Docker. Instead of a Vagrantfile, you’d define your environment using a Containerfile
(similar to a Dockerfile).
Explanation:
Podman allows you to define your environment using a Containerfile. This file contains instructions on how to build a container image, including the base image, software installations, and configuration settings. By using a Containerfile, you can create reproducible and portable environments. The benefit here is the reduced overhead of containerization compared to virtualization. Containers share the host OS kernel, leading to faster boot times and lower resource consumption.
Code Example (Containerfile):
# Use a base image
FROM rockylinux:8
# Install necessary packages
RUN dnf update -y &&
dnf install -y httpd vim
# Expose port 80
EXPOSE 80
# Start the Apache web server
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Building and Running the Container:
- Save the above content as
Containerfile
in a directory. - Build the image:
podman build -t my-httpd-image .
- Run the container:
podman run -d -p 8080:80 my-httpd-image
This example creates a container image based on Rocky Linux 8, installs the Apache web server, exposes port 80, and starts the server. You can then access the web server on your host machine at port 8080.
2. Using libvirt with virt-install
libvirt is a virtualization management API, daemon and command line tool for managing KVM, Xen, and other virtualization technologies. It provides a stable and consistent way to manage virtual machines across different hypervisors. virt-install
is a command-line tool for creating new virtual machines using libvirt.
Explanation:
libvirt offers a more direct approach to managing virtual machines compared to Vagrant. It allows you to create, manage, and monitor VMs through a unified API. virt-install
provides a convenient way to create new VMs from the command line, specifying parameters such as the operating system, memory, CPU, and storage. While it requires more manual configuration than Vagrant, it gives you finer-grained control over your virtual machines.
Code Example:
sudo virt-install
--name my-rocky-vm
--memory 2048
--vcpus 2
--os-variant rocky8.4
--location 'http://dl.rockylinux.org/pub/rocky/8.7/BaseOS/x86_64/os/'
--disk path=/var/lib/libvirt/images/my-rocky-vm.qcow2,size=20
Explanation of Parameters:
--name my-rocky-vm
: Specifies the name of the virtual machine.--memory 2048
: Allocates 2048 MB of RAM to the VM.--vcpus 2
: Assigns 2 virtual CPUs to the VM.--os-variant rocky8.4
: Specifies the operating system variant (Rocky Linux 8.4 in this case).--location 'http://dl.rockylinux.org/pub/rocky/8.7/BaseOS/x86_64/os/'
: Provides the URL to the installation source. Note: Adjust the URL to point to the correct Rocky Linux version.--disk path=/var/lib/libvirt/images/my-rocky-vm.qcow2,size=20
: Creates a 20 GB disk image for the VM.
After running this command, the installation process will begin. You can then connect to the VM using virsh console my-rocky-vm
or a graphical VNC client. This approach to Install Vagrant on Rocky Linux 8 offers a more fundamental and potentially more powerful approach.
These alternatives, Podman and libvirt, offer different ways to achieve similar goals to Vagrant on Rocky Linux 8. Choose the tool that best fits your specific needs and level of comfort with virtualization and containerization technologies.