Cybersecurity Updates & Tools

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.