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.

In this guide, I’ll take you through different ways to install the latest release of Vagrant on Ubuntu 18.04, Debian 9 & Kali Linux distributions. Let’s get started.

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 18.04 / Debian 9

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

Install the latest Vagrant from a .deb package

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

Download the latest release of Vagrant with wget

VER="2.2.0"
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

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
sudo apt-get update

Once the repo is added, proceed to install vagrant

 sudo apt-get install vagrant

Using Vagrant

After the installation, you can check the version:

$ vagrant --version

Vagrant  2.2.0

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 ubuntu-18.04
cd ubuntu-18.04
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 = false
  config.vm.network "private_network", ip: "192.168.18.50"
  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