You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this guide, I’ll take you through different ways to install the latest release of Vagrant on Ubuntu 20.04/18.04, Debian 10 & Kali 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

How to install latest VirtualBox on Kali Linux Rolling

How to install the latest VirtualBox on Ubuntu / Debian

Install KVM on CentOS 7 / Ubuntu 16.04 / Debian 9 / SLES 12 / Arch Linux

Install Vagrant from a .deb package

The first and quick method of installing latest Vagrant on Ubuntu 18.04, Debian 10 and Kali Linux is from .deb package. Check Vagrant Downloads page for the latest release of Vagrant. Here we’ll install v2.2.9

Download the latest release of Vagrant with wget

VER="2.2.9"
wget https://releases.hashicorp.com/vagrant/${VER}/vagrant_${VER}_x86_64.deb

Once the package is downloaded, install the package with the dpkgcommand:

sudo dpkg -i vagrant_${VER}_x86_64.deb

If there are some missing dependencies, run:

sudo apt -f install

Install the latest Vagrant from apt repository

The other method of installing Vagrant on Debian and its derivatives is from an apt repository. One repository I found to be working is one provided on https://vagrant-deb.linestarve.com. This enables you to update installed version of Vagrant using the aptpackage manager.

Disclaimer: This is an unofficial Debian repository for Vagrant, hosted by Wolfgang Faust. Add the repository to your system using the command:

sudo bash -c 'echo deb https://vagrant-deb.linestarve.com/ any main > /etc/apt/sources.list.d/wolfgang42-vagrant.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key AD319E0F7CFFA38B4D9F6E55CE3F3DE92099F7A4 D2BABDFD63EA9ECAB4E09C7228A873EA3C7C705F
sudo apt-get update

Once the repo is added, proceed to install vagrant:

 sudo apt -y install vagrant

Using Vagrant on Ubuntu / Debian / Kali Linux

After the installation, you can check the version:

$ vagrant --version
Vagrant  2.2.9

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

$ vagrant box add offensive-security/kali-linux

To Download Ubuntu 18.04 Vagrant image, use:

$ vagrant box add generic/ubuntu1804

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 :

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'

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

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.

Also read:

Using Vagrant with Libvirt on Linux

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF