Vagrant is a command-line tool that makes it easy to build and manage virtual machine environments. Developers use it to create a local setup that matches the production server exactly. This removes the classic “works on my machine” problem.
By default, Vagrant works with VirtualBox, Hyper-V, and Docker. You can add support for other providers like VMware, KVM, or AWS through plugins.
This guide will show you how to install Vagrant on Ubuntu 18.04 using VirtualBox as the provider. It also covers how to spin up your first virtual machine and use the most common Vagrant commands.
<strong>Prerequisite:</strong> You need sudo access on your Ubuntu machine.
Install Vagrant on Ubuntu 18.04
Follow these three steps to get Vagrant installed and running.
Step 1: Install VirtualBox
Vagrant needs a provider to create virtual machines. We will use VirtualBox, which is available in the default Ubuntu repositories.
Install it with:
bashsudo apt install virtualbox
If you want the latest version of VirtualBox from Oracle’s own repositories, check the official VirtualBox download page for instructions.
Step 2: Download and Install Vagrant
The Vagrant version in the Ubuntu repositories is outdated. Instead, download the latest release directly from the official HashiCorp website.
At the time of writing, the latest version is 2.2.6. Always check the Vagrant downloads page to confirm the current release before running these commands.
Update your package lists first:
bashsudo apt update
Download the Vagrant package using curl:
bashcurl -O https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.deb
Install the downloaded package:
bashsudo apt install ./vagrant_2.2.6_x86_64.deb
Step 3: Verify the Installation
Check that Vagrant installed correctly by printing the version number:
bashvagrant --version
Output:
Vagrant 2.2.6
Create Your First Vagrant Project
With Vagrant ready, you can now set up a development environment in just a few steps.
Start by creating a project directory and switching into it:
bashmkdir ~/my-first-vagrant-projectcd ~/my-first-vagrant-project
A Vagrantfile is the configuration file Vagrant uses to describe how your virtual machine should be set up. It is written in Ruby and sits at the root of your project folder.
Initialize a new Vagrantfile using the vagrant init command. You also specify the box you want to use. Boxes are pre-built machine images that Vagrant downloads and uses as a base. You can find public boxes at the Vagrant Cloud box catalog.
This example uses the centos/7 box:
bashvagrant init centos/7
Start the virtual machine:
bashvagrant up
Vagrant will download the box if it is not already cached, then boot the machine. Your project directory is automatically mounted inside the VM at /vagrant, so any file you edit on the host is available inside the machine straight away.
Common Vagrant Commands
Once your machine is running, these are the commands you will use most often:
bashvagrant ssh
This opens an SSH session directly into the running VM. No passwords or keys required.
bashvagrant halt
This shuts down the running machine cleanly while keeping all the VM files on disk.
bashvagrant destroy
This stops the machine and removes all the resources created for it. Your Vagrantfile stays in place, so you can rebuild it at any time with vagrant up.
You now have Vagrant installed and a working virtual machine running on Ubuntu 18.04. The combination of Vagrant and VirtualBox gives you a powerful local development setup that is easy to share with your team. Leave a comment below if you run into any setup issues.


