DevOps Elastic Hayway
Document

SUBSCRIBE TO GET FULL ACCESS TO THE E-BOOKS FOR FREE 🎁SUBSCRIBE NOW

Professional Dropdown with Icon

SUBSCRIBE NOW TO GET FREE ACCESS TO EBOOKS

LinuxLesson 1 / 123 min readUpdated September 13, 2026

Vagrant

Vagrant simplifies the creation and management of portable virtual development environments across multiple providers including VirtualBox. It allows teams to define infrastructure as code and spin up identical environments quickly. This tutorial explains how to install Vagrant and VirtualBox on Ubuntu 24.04 LTS and use them effectively.

Prerequisites

Before starting, ensure your system meets these requirements. Virtualization must be enabled in the BIOS or UEFI settings of your laptop or server. You need an Ubuntu 24.04 LTS installation with at least 8 GB of RAM and 20 GB of free disk space. Administrative privileges via sudo are required for package installation. A stable internet connection is necessary to download packages and boxes.

Step 1: Update the System

Begin by updating all existing packages to their latest versions. This prevents conflicts during the installation of new software.

sudo apt update && sudo apt upgrade -y

After the command completes, reboot the system if a kernel update was applied.

Step 2: Install VirtualBox

VirtualBox serves as the default provider for Vagrant on local machines. Add the official Oracle repository to obtain the latest stable version.

sudo apt install -y curl gnupg software-properties-common
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /etc/apt/keyrings/oracle_vbox.gpg
echo "deb [signed-by=/etc/apt/keyrings/oracle_vbox.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 -y virtualbox-7.0

Verify the installation by checking the version.

vboxmanage --version

Expected output shows the current VirtualBox release number, confirming successful installation.

Step 3: Install Vagrant

Download and install the latest Vagrant package from the official HashiCorp repository.

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/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

Confirm the installation.

vagrant --version

The output displays the installed Vagrant version, typically 2.4 or newer as of late 2026.

Step 4: Create a Vagrant Project

Create a dedicated directory for your project and initialize a Vagrant environment.

mkdir ~/vagrant-project && cd ~/vagrant-project
vagrant init ubuntu/jammy64

This command generates a Vagrantfile that references the official Ubuntu 22.04 box. Edit the file to customize settings such as memory allocation.

nano Vagrantfile

Inside the file, uncomment and adjust the provider section:

config.vm.provider "virtualbox" do |vb|
  vb.memory = "2048"
  vb.cpus = 2
end

Step 5: Start and Access the Environment

Launch the virtual machine with the following command.

vagrant up

Vagrant downloads the box on first run, provisions the VM, and starts it. Access the machine via SSH.

vagrant ssh

Once inside, you can install packages or run commands as you would on any Ubuntu system. Exit with exit when finished.

Step 6: Basic Provisioning

Add a shell provisioner in the Vagrantfile to automate setup tasks such as installing nginx.

config.vm.provision "shell", inline: <<-SHELL
  apt-get update
  apt-get install -y nginx
SHELL

Re-run vagrant up --provision or vagrant provision to apply changes. This ensures every team member receives the same configured environment.

Common Errors

  • Virtualization not enabled in BIOS causes Vagrant to fail during VM creation. Enable VT-x or AMD-V in firmware settings.
  • Port 22 conflict occurs when another process uses the SSH port. Change the forwarded port in the Vagrantfile to 2222.
  • Box download failures result from network restrictions. Use a corporate proxy or download the box manually.
  • Permission errors during installation are resolved by ensuring the current user belongs to the vboxusers group.

Going Further

  • Integrate Vagrant with Ansible or Puppet for advanced configuration management.
  • Use multi-machine setups to simulate production clusters with separate web and database nodes.
  • Combine Vagrant with Terraform for hybrid local and cloud workflows on AWS or Azure.
  • Explore synced folders and port forwarding to streamline local development with containerized applications.

Conclusion

Vagrant provides a reliable way to create consistent, reproducible development environments on Ubuntu 24.04 LTS. By following the steps above, you establish a solid foundation for local testing and team collaboration. Regular updates to both VirtualBox and Vagrant ensure continued compatibility and security.

FAQ

What is the recommended provider for local Vagrant use?

VirtualBox remains the most straightforward and widely supported provider for local development on Ubuntu 24.04 LTS.

Can I use a different base box than ubuntu/jammy64?

Yes. Official boxes from HashiCorp or community boxes for CentOS, Debian, or custom images can be specified in the Vagrantfile.

How do I destroy and recreate an environment cleanly?

Run vagrant destroy -f followed by vagrant up. This removes all traces of the previous VM and provisions a fresh instance.

Is Vagrant suitable for production workloads?

Vagrant targets development and testing environments. Production workloads should use dedicated orchestration tools such as Kubernetes or cloud-native services.

How often should Vagrant boxes be updated?

Check for updates monthly using vagrant box update to receive security patches and newer package versions in the base image.

Retour parcours Linux — hub de la série et leçons sœurs.

Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *