How To Install Vagrant on Ubuntu 22.04/20.04/18.04

Posted on 151 views

In this guide, I’ll take you through different ways to install the latest release of Vagrant on Ubuntu 22.04/20.04/18.04 Linux distributions. Vagrant is an open source tool for building and managing virtual machine environments in an easy-to-use single workflow. Vagrant focuses on automation, lowering development environment setup time and increasing production parity.

Vagrant works with VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. The software is written in Ruby and actively developed by HashiCorp.

Setup Pre-requisite

Note that Vagrant depends on existing hypervisor on your system, this can be VirtualBox, KVM, or VMware. We have the following guides to help you with the installation of these hypervisors

Install Vagrant on Ubuntu 22.04/20.04/18.04

The other method of installing Vagrant on Debian and its derivatives is from an apt repository.

Install repository addition dependencies:

sudo apt update
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common

Add the official Vagrant APT repository to your system:

curl -fsSL | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] $(lsb_release -cs) main"

Once the repo is added, proceed to install vagrant:

sudo apt update
sudo apt install vagrant

Installation should take few seconds to complete:

Hit:1 focal-security InRelease
Get:2 focal InRelease [265 kB]
Hit:3 focal InRelease
Hit:4 focal-updates InRelease
Hit:5 focal-backports InRelease
Fetched 265 kB in 1s (340 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 47 not upgraded.
Need to get 40.9 MB of archives.
After this operation, 115 MB of additional disk space will be used.
Get:1 focal/main amd64 vagrant amd64 2.2.16 [40.9 MB]
Fetched 40.9 MB in 1s (33.4 MB/s)
Selecting previously unselected package vagrant.
(Reading database ... 65336 files and directories currently installed.)
Preparing to unpack .../vagrant_2.2.16_amd64.deb ...
Unpacking vagrant (2.2.16) ...
Setting up vagrant (2.2.16) ...

Using Vagrant on Ubuntu 22.04|20.04|18.04

After the installation, you can check the version:

$ vagrant --version
Vagrant 2.3.1

Download a test Vagrant Box. In this example, I’ll download Kali Linux:

$ vagrant box add offensive-security/kali-linux

To Download Ubuntu 20.04 Vagrant image, use:

$ vagrant box add generic/ubuntu2204 --provide=virtualbox

To launch a VM using Vagrant, you’ll need to create a Vagrantfile. The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision a Virtual Machine.

mkdir boxes && cd boxes
touch Vagrantfile

Below is an example of Vagrantfile content

# -*- mode: ruby -*-
# vi: set ft=ruby :


Vagrant.configure("2") do |config|
  ##### DEFINE VM #####
  config.vm.define "ubuntu-01" do |config|
  config.vm.hostname = "ubuntu-01" = "generic/ubuntu2204"
  config.vm.box_check_update = true

Bring up the VM by running:

$ vagrant up

Then ssh to the instance with

$ vagrant ssh

To shutdown VM, use:

$ vagrant halt

Hibernate VM

$ vagrant suspend

Set VM to initial state by cleaning all data

$ vagrant destroy

That’s all, enjoy using Vagrant and read more on Vagrant Documentation link.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.