Vagrant is an open source command line tool for building and managing virtual machine environments. By default Vagrant can provision machines on top of VirtualBox, Hyper-V and Docker but many other providers such as Libvirt (KVM), VMware and AWS can be installed via the Vagrant plugin system.

Vagrant is mostly used by developers to easily set up a development environment, that matches the production environment.

This tutorial explains how to install Vagrant on a Debian 9 machine. We’ll be using the VirtualBox provider, which is the default provider for Vagrant.

Install Vagrant on Debian

The Vagrant package which is available in the Debian’s repositories is pretty outdated. We’ll be download and install the latest version of Vagrant from the official Vagrant site.

At the time of writing this article, the latest stable version of Vagrant is version 4.0.0. Before continuing with the next steps you should check the Vagrant Download page to see if a newer version is available.

To verify that the installation was successful run the following command which will print the Vagrant version:

vagrant --version

The output should look something like this:

Vagrant 2.2.3

Getting Started with Vagrant

Now that Vagrant is installed on your Debian machine we let’s see how to create a development environment which is the most common use case.

The first step is to create a directory which will be the project root directory and hold the Vagrantfile file. Vagrantfile is a Ruby file that describes how to configure and provision the virtual machine.

Create the project directory and switch to it with:

mkdir ~/my-first-vagrant-project
cd ~/my-first-vagrant-project

The next step is to initialize a new Vagrantfile using the vagrant init command and specify the box we wish to use.

Boxes are the package format for the Vagrant environments and are provider-specific. You can find a list of publicly available Vagrant Boxes on the Vagrant box catalog page.

In this example, we will use the centos/7 box. Run the following command to initialize a new Vagrantfile:

vagrant init centos/7

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

You can open the Vagrantfile, read the comments and make adjustment according to your needs.

Now we can run the vagrant up command which will create and configure the virtual machine according to the Vagrantfile.