In this tutorial, we want to show you to Install and Use Vagrant on AlmaLinux 8.
Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.
Steps To Install and Use Vagrant on AlmaLinux 8
To install Vagrant on your server, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with AlmaLinux 8.
Also, you need to install VirtualBox on your server. For this, you can check our article How To Install VirtualBox on AlmaLinux 8.
Set up Vagrant on AlmaLinux 8
To install vagrant, you need to install the yum-utils package on your server:
sudo dnf install -y yum-utils
Add Vagrant Repository
Then, use the command below to add the Vagrant repo on AlmaLinux 8:
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
Next, you can install the latest Vagrant with the following command:
sudo dnf -y install vagrant
Now you can verify your installation by checking the Vagrant version:
In your output you will see:
Output Vagrant 2.3.4
You have successfully installed Vagrant on AlmaLinux 8, let’s see how to use it.
How To Use Vagrant
At this point, we want to show you how to use Vagrant by creating a development environment.
First, you need to create a file to save the Vagrant file there. To do this, run the following command:
Then, you need to initialize a new Vagrantfile and specify the box you wish to use on AlmaLinux 8.
Boxes are the package format for the Vagrant environments and are provider-specific.
You can check the list of available Vagrant Boxes on the Vagrant Catalog page.
In this example, we want to use ubuntu/trusty64.
Switch to your Vagrant project directory on AlmaLinux 8 with the following command:
Now initialize the Vagrantfile with the following command:
vagrant init ubuntu/trusty64
In your output you will see:
Output 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 `vagrantup.com` for more information on using Vagrant.
You can open the Vagrantfile with your favorite text editor and make changes according to your needs on AlmaLinux 8.
Run the following command to create and configure the virtual machine as defined in the Vagrantfile:
Output ==> default: Configuring and enabling network interfaces... ...
Vagrant mounts the project directory at /vagrant in the virtual machine. This allows you to work on the project’s files on your host machine.
You can use the following command to ssh to your virtual machine:
Also, you can stop the virtual machine with the command below:
If you want to stop and destroy all resources that were created during the creation of the machine, you can use the following command:
At this point, you have learned to Install and Use Vagrant on AlmaLinux 8.
Hope you enjoy using it.
May these articles on the Orcacore website be useful for you: