Vagrant provides a consistent, portable development environment by automating the creation and provisioning of virtual machines. This guide installs Vagrant and VirtualBox on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS desktop or server
- CPU with hardware virtualisation enabled (VT-x/AMD-V)
- A user with sudo privileges
Step 1 – Add the HashiCorp Repository
Add the HashiCorp repo (already added if you installed Terraform):
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
Step 2 – Install Vagrant
Install from the HashiCorp repo:
sudo apt update
sudo apt install vagrant -y
vagrant --version
Step 3 – Install VirtualBox
Add the VirtualBox repository and install:
sudo apt install virtualbox -y
Or from Oracle’s repo for the latest version:
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /usr/share/keyrings/oracle-virtualbox.gpg
echo "deb [signed-by=/usr/share/keyrings/oracle-virtualbox.gpg] https://download.virtualbox.org/virtualbox/debian noble contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
sudo apt update && sudo apt install virtualbox-7.0 -y
Step 4 – Create a Vagrantfile
Create a directory and initialise a Vagrantfile:
mkdir ~/vagrant-ubuntu && cd ~/vagrant-ubuntu
vagrant init ubuntu/jammy64
Step 5 – Start the Virtual Machine
Boot the VM:
vagrant up
Step 6 – SSH into the VM
Connect with:
vagrant ssh
Step 7 – Provision with Shell Scripts
Add provisioning to Vagrantfile:
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y nginx
SHELL
Apply provisioning:
vagrant provision
Conclusion
Vagrant and VirtualBox are now installed on Ubuntu 24.04 LTS. Vagrant lets you create reproducible development environments and share them as Vagrantfiles with your team.