Recently, I wrote a post about how to install a Linux distribution. You can find the post here: 7 easy steps to install Ubuntu on a VM.
Today, I would like to share with you a different approach in setting up your lab environment with Vagrant and VirtualBox. Here you will mostly use the command line (CLI) and not the graphical user interface (GUI).

Table of Contents
1. Install the virtualization software
The first step is to install the virtualization software. You can choose from different options like VirtualBox, VMware.
In my setup, I will use VirtualBox. To install VirtualBox in Ubuntu 22.04, run the below command.
# Install VirtualBox
wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | gpg --dearmor | sudo tee /usr/share/keyrings/oracle-virtualbox-2016.gpg
echo "deb [signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
sudo apt update && sudo apt install virtualbox-6.1

Check if the installation was successful.
vboxmanage -v

2. Install Vagrant
The second step is to install Vagrant. Vagrant is an open-source software which helps you to easily deploy and manage VMs from the command line.
To install Vagrant in Ubuntu 22.04, run the below command.
# Install Vagrant
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /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 vagrant

Check if the installation was successful.
vagrant -v

3. Create a new directory and the Vagrantfile file
The third step is to create a new directory which will be used by Vagrant. In this directory, we need to create a new text file with the name Vagrantfile. In this file you will define the details for the virtual machine (VM).
mkdir lab
cd lab/

Define the details for the new VM in the Vagrantfile file.
cat >> Vagrantfile <<EOF
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "ubuntu" do |ubuntu|
ubuntu.vm.box = "ubuntu/jammy64"
ubuntu.vm.network "private_network", ip: "192.168.59.10"
ubuntu.vm.hostname = "ubuntu"
ubuntu.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
end
end

4. Start the VM
The fourth step is to start the VM. For this you need to run the following command.
vagrant up

When you run the above command for the first time, it will take some time until it finishes. The box is downloaded from HashiCorp Vagrant Cloud. Depending on your Internet speed, it may take between 5 to 10 minutes, so be patient.
5. Connect (SSH) to the VM
After the VM is up and running, you can connect to it with SSH.
You need to run a command similar to the below one:
vagrant ssh ubuntu

6. Discover your Linux box
The sixth and final step is to discover your new Linux distribution.
cat /etc/os-release
whoami

7. Some useful vagrant commands that you can use
To check the status of your VM, use the following command:
vagrant status

To pause your VM, use the following command:
vagrant suspend


To stop the VM, use the following command:
vagrant halt

To delete the VM, use the following command:
vagrant destroy

If you want to create 2 or more VMs, you can specify their details in the same Vagrantfile file.

I hope you find this post helpful.
If you struggle to set up your lab, please share your issue in the comments and I will try to help you.