How To

Install Vagrant on Ubuntu: Setup and Getting Started Guide

If your team needs identical development environments across different operating systems, Vagrant is the tool that makes it effortless. Vagrant is a command-line tool by HashiCorp for building and managing virtual machines in a reproducible, shareable way. It supports multiple providers out of the box, including VirtualBox, Hyper-V, and Docker with additional providers like VMware, AWS, and Libvirt available through its plugin system. This guide walks through how to install Vagrant on Ubuntu and launch your first virtual machine in minutes.

Install Vagrant on Ubuntu from the Official Package

Vagrant requires a virtualization provider. VirtualBox is the default and the simplest option to get running. If it is not already on your system, install it first:

bashsudo apt updatesudo apt install virtualbox

The Vagrant package in Ubuntu’s default repositories tends to lag behind the current release. For the latest stable version, download the official .deb package directly from HashiCorp’s release server:

bashcurl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb

Once the download finishes, install it with apt:

bashsudo apt install ./vagrant_2.2.9_x86_64.deb

Verify the installation by printing the Vagrant version:

bashvagrant --version

A successful install outputs the version number; for example, Vagrant 2.2.9. Always check the official Vagrant downloads page before running the commands above to confirm you are grabbing the latest available release.

Set Up Your First Vagrant Project

A Vagrant project lives in its own directory and is defined by a Vagrantfile, a Ruby-based configuration file that describes how your virtual machine should be built and provisioned. Create a project directory and navigate into it:

bashmkdir ~/my-vagrant-projectcd ~/my-vagrant-project

Initialize the project using a specific Vagrant box. Boxes are pre-packaged base images that Vagrant uses to spin up machines. They are provider-specific, and you can browse thousands of community and official boxes at the Vagrant box catalog. This example uses the CentOS 8 box:

bashvagrant init centos/8

This creates a Vagrantfile in your project directory. Open it to review the default settings and adjust them to your needs. When ready, bring the virtual machine online:

bashvagrant up

Vagrant downloads the box image if not already cached, boots the VM, and configures the network. It also mounts your project directory inside the VM at /vagrant automatically, any file you edit on your host machine is immediately visible inside the environment.

Essential Vagrant Commands

Once your virtual machine is running, these are the commands you will reach for most often:

CommandWhat It Does
vagrant sshOpens an SSH session directly into the running VM
vagrant haltGracefully shuts down the VM, preserving its state
vagrant destroyRemoves the VM and all associated resources
vagrant statusShows the current state of the VM

Tip: Use vagrant halt when you plan to resume work later. vagrant destroy wipes the machine entirely, you will need to run vagrant up again and wait for the full provisioning cycle from scratch.

Vagrant removes the friction of setting up and maintaining development environments manually. Once you have a working Vagrantfile, any team member can replicate your exact environment with a single vagrant up command, regardless of whether they are on Windows, macOS, or Linux. That consistency is invaluable on collaborative projects. From here, explore Vagrant’s provisioning support for tools like Ansible, Chef, and Shell scripts to fully automate the environment inside your VM. Questions about your setup? Drop a comment below.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

3 weeks ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

3 weeks ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

3 weeks ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

2 months ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

2 months ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago