Vagrant is a tool built by HashiCorp that automates the creation and management of portable development environments. Instead of manually installing an operating system inside VirtualBox, you define everything in a single configuration file called a Vagrantfile, run one command, and have a fully working virtual machine ready in minutes. This guide walks you through running Rocky Linux 10 and AlmaLinux 10 virtual machines using Vagrant with VirtualBox as the hypervisor backend.
Vagrant pulls pre-built OS images (called “boxes”) from Vagrant Cloud, applies your configuration for CPU, memory, networking, and shared folders, then boots the VM automatically. You get SSH access out of the box with no manual setup required. When you are done, tear the whole thing down with a single command and rebuild it whenever you need to.
Prerequisites
Before you begin, confirm the following are in place:
- A Linux, macOS, or Windows workstation with at least 4 GB of free RAM
- VirtualBox 7.x installed and working – verify with
vboxmanage --version - Internet access to download Vagrant and box images
- Administrative or sudo privileges on your workstation
If VirtualBox is not installed yet, grab it from the official download page or install it through your package manager.
Step 1 – Install Vagrant from HashiCorp Repository
Always install Vagrant from the official HashiCorp repository rather than your distribution’s default packages. The distro packages tend to lag behind significantly.
Install Vagrant on Debian / Ubuntu
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 -y vagrant
Install Vagrant on RHEL / Fedora / Rocky / Alma
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum install -y vagrant
Install Vagrant on macOS
brew tap hashicorp/tap
brew install hashicorp/tap/vagrant
Verify the installation:
vagrant --version
You should see output similar to:
Vagrant 2.4.x
Step 2 – Initialize a Rocky Linux 10 or AlmaLinux 10 Vagrant Project
Create a dedicated directory for your project and initialize it with a Vagrant box. Official boxes for Rocky Linux and AlmaLinux are published on Vagrant Cloud.
For Rocky Linux 10
mkdir -p ~/vagrant/rocky10 && cd ~/vagrant/rocky10
vagrant init rockylinux/10
For AlmaLinux 10
mkdir -p ~/vagrant/alma10 && cd ~/vagrant/alma10
vagrant init almalinux/10
The vagrant init command generates a Vagrantfile in the current directory. This file is the single source of truth for your VM configuration.
Verify: Confirm the file was created.
ls -la Vagrantfile
Step 3 – Configure the Vagrantfile
The default Vagrantfile is full of comments. Below is a clean, production-style configuration that sets memory, CPUs, networking, and synced folders. Open the Vagrantfile in your editor and replace its contents:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Use Rocky Linux 10 - swap to almalinux/10 if you prefer AlmaLinux
config.vm.box = "rockylinux/10"
# Set a hostname
config.vm.hostname = "rocky10-lab"
# Private network - accessible only from the host
config.vm.network "private_network", ip: "192.168.56.10"
# Port forwarding - forward guest port 80 to host port 8080
config.vm.network "forwarded_port", guest: 80, host: 8080
# Synced folder - share a local directory with the VM
config.vm.synced_folder "./data", "/vagrant_data", create: true
# VirtualBox provider settings
config.vm.provider "virtualbox" do |vb|
vb.name = "rocky10-lab"
vb.memory = "2048"
vb.cpus = 2
end
end
Key settings explained:
- config.vm.box – the box name from Vagrant Cloud
- config.vm.hostname – sets the hostname inside the guest OS
- private_network – creates a host-only network so you can reach the VM at a static IP
- forwarded_port – maps a port on the guest to a port on the host machine
- synced_folder – shares a directory between host and guest, with
create: trueto auto-create the local folder if it does not exist - vb.memory / vb.cpus – allocates RAM (in MB) and CPU cores to the VM
Step 4 – Boot the Virtual Machine
Start the VM with:
vagrant up
On the first run, Vagrant downloads the box image from Vagrant Cloud (this takes a few minutes depending on your connection), imports it into VirtualBox, applies your configuration, and boots the machine.
Verify the VM is running:
vagrant status
Expected output:
Current machine states:
default running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine.
Step 5 – SSH into the VM
Connect to the running machine over SSH:
vagrant ssh
You land in the VM as the vagrant user with passwordless sudo access. Confirm you are inside the guest:
cat /etc/os-release | head -4
free -h
nproc
You should see Rocky Linux 10 (or AlmaLinux 10) details, 2 GB of memory, and 2 CPUs matching your Vagrantfile settings. Type exit to return to your host.
Step 6 – Manage the VM Lifecycle
Here are the core commands you will use daily:
| Command | What It Does |
|---|---|
vagrant up | Start or create the VM |
vagrant ssh | SSH into the running VM |
vagrant halt | Gracefully shut down the VM |
vagrant reload | Restart the VM and re-apply Vagrantfile changes |
vagrant suspend | Save the VM state to disk (like hibernate) |
vagrant resume | Resume a suspended VM |
vagrant destroy | Delete the VM completely – the box image stays cached |
vagrant provision | Re-run provisioning scripts without rebooting |
Verify after halt:
vagrant halt
vagrant status
Status should show poweroff.
Step 7 – Provisioning with Shell Scripts
Vagrant can run scripts automatically when a VM is first created or whenever you trigger provisioning. This saves you from repeating the same setup steps manually. Add a provisioner block to your Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "rockylinux/10"
config.vm.hostname = "rocky10-lab"
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
# Inline shell provisioner
config.vm.provision "shell", inline: <<-SHELL
dnf update -y
dnf install -y vim git curl wget net-tools bind-utils
systemctl enable --now firewalld
echo "Provisioning complete."
SHELL
end
If the VM is already running, apply the provisioner without destroying it:
vagrant provision
For larger setups, point to an external script file instead of inline commands:
config.vm.provision "shell", path: "bootstrap.sh"
Verify provisioning ran:
vagrant ssh -c "rpm -q git vim-enhanced"
Step 8 – Multi-Machine Vagrantfile for Lab Environments
One of Vagrant’s strongest features is spinning up multiple VMs from a single Vagrantfile. This is ideal for building lab environments – think a web server, a database server, and a load balancer all defined in one file.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Node 1 - Web Server (Rocky Linux 10)
config.vm.define "web" do |web|
web.vm.box = "rockylinux/10"
web.vm.hostname = "web01"
web.vm.network "private_network", ip: "192.168.56.11"
web.vm.network "forwarded_port", guest: 80, host: 8081
web.vm.provider "virtualbox" do |vb|
vb.name = "web01"
vb.memory = "1024"
vb.cpus = 1
end
web.vm.provision "shell", inline: <<-SHELL
dnf install -y httpd
systemctl enable --now httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
SHELL
end
# Node 2 - Database Server (AlmaLinux 10)
config.vm.define "db" do |db|
db.vm.box = "almalinux/10"
db.vm.hostname = "db01"
db.vm.network "private_network", ip: "192.168.56.12"
db.vm.provider "virtualbox" do |vb|
vb.name = "db01"
vb.memory = "2048"
vb.cpus = 2
end
db.vm.provision "shell", inline: <<-SHELL
dnf install -y mariadb-server
systemctl enable --now mariadb
SHELL
end
# Node 3 - Monitoring (Rocky Linux 10)
config.vm.define "monitor" do |mon|
mon.vm.box = "rockylinux/10"
mon.vm.hostname = "monitor01"
mon.vm.network "private_network", ip: "192.168.56.13"
mon.vm.provider "virtualbox" do |vb|
vb.name = "monitor01"
vb.memory = "1024"
vb.cpus = 1
end
end
end
Manage individual machines by name:
# Start only the web server
vagrant up web
# SSH into the database server
vagrant ssh db
# Destroy only the monitoring node
vagrant destroy monitor -f
# Start everything
vagrant up
Verify all machines are running:
vagrant status
You should see all three machines listed with their state.
Step 9 – Port Forwarding in Detail
Port forwarding lets you access services running inside the VM from your host browser or tools. The basic syntax is:
config.vm.network "forwarded_port", guest: 80, host: 8080
Some practical examples:
# Forward guest port 443 to host port 8443
config.vm.network "forwarded_port", guest: 443, host: 8443
# Forward guest port 3306 (MariaDB) to host port 33060
config.vm.network "forwarded_port", guest: 3306, host: 33060
# Forward with a specific host IP (bind to localhost only)
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
# Auto-correct port collisions - Vagrant picks another port if 8080 is taken
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
After modifying port forwarding in the Vagrantfile, apply changes with:
vagrant reload
Verify port forwarding:
# From your host machine
curl -I http://localhost:8080
Step 10 – Box Management
Vagrant caches downloaded box images locally so subsequent vagrant up runs skip the download. You manage cached boxes with these commands:
# List all locally cached boxes
vagrant box list
# Add a box manually without initializing a project
vagrant box add rockylinux/10
vagrant box add almalinux/10
# Check for updated versions of cached boxes
vagrant box update
# Remove a specific box version
vagrant box remove rockylinux/10
# Remove all old versions, keep only the latest
vagrant box prune
Verify your box cache:
vagrant box list
Sample output:
almalinux/10 (virtualbox, 10.0.20250101)
rockylinux/10 (virtualbox, 10.0.20250101)
Troubleshooting Common Issues
VT-x/AMD-V not available
If vagrant up fails with a virtualization error, hardware virtualization is likely disabled in your BIOS/UEFI settings. Reboot into firmware settings and enable Intel VT-x or AMD-V.
Check from Linux:
egrep -c '(vmx|svm)' /proc/cpuinfo
A result of 0 means virtualization is disabled.
Box download fails or times out
If the box download stalls, you can download it manually and add it:
# Download the box file manually with wget or a browser, then:
vagrant box add rockylinux/10 /path/to/downloaded-box-file.box
Vagrant version mismatch with VirtualBox
After a VirtualBox upgrade, Vagrant may lose compatibility. Update Vagrant to the latest version:
# On RHEL-based systems
sudo yum update vagrant
# On Debian-based systems
sudo apt update && sudo apt upgrade vagrant
# On macOS
brew upgrade hashicorp/tap/vagrant
Private network not working
VirtualBox requires a host-only network adapter. If you get errors about the network, create one manually:
vboxmanage hostonlyif create
vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1
Then run vagrant reload.
Synced folder mount fails
If synced folders fail to mount, install the VirtualBox Guest Additions plugin for Vagrant:
vagrant plugin install vagrant-vbguest
vagrant reload
SSH connection timeout
If vagrant ssh hangs, check that the VM actually booted successfully:
vagrant up --debug 2>&1 | tail -50
Look for errors related to SSH key insertion or network configuration. A common fix is to destroy and recreate:
vagrant destroy -f && vagrant up
Checking Vagrant environment health
Run the built-in validation to catch Vagrantfile syntax errors before booting:
vagrant validate
Expected output:
Vagrantfile validated successfully.
Wrapping Up
You now have a solid workflow for spinning up Rocky Linux 10 and AlmaLinux 10 virtual machines using Vagrant and VirtualBox. From single-node development boxes to multi-machine lab environments with automated provisioning, Vagrant removes the repetitive manual work and gives you reproducible infrastructure on your local workstation. Define it once in a Vagrantfile, commit it to version control, and every team member gets an identical environment.


























































Thanks for your support
Welcome.