Introduction

Vagrant is a software application that creates an operating system environment using virtualization technology.

Vagrant uses a command line interface to load, prepare, and launch a virtual environment, called a Vagrant Box. There are many preconfigured Vagrant boxes available for download. You can also start with a basic box and add your own configuration.

This guide will walk you thru how to install Vagrant on Ubuntu 18.04 (Bionic Beaver).

installation steps for Vagrant on Ubuntu linux

Prerequisites

  • Access to a user account with sudo privileges
  • A terminal window / command line (Ctrl-Alt-T)

Steps to Install Vagrant on Ubuntu

Install VirtualBox

VirtualBox is a software utility that allows you to run an operating system inside of an operating system. It does this by creating a virtual environment. Since Vagrant creates virtual operating systems, it needs a tool like VirtualBox to manage the virtual operating systems.

In a terminal window, enter the following:

sudo apt install virtualbox

The system should download and install VirtualBox software.

Note: There are other virtualization applications available. If you prefer, you could use KVM, VMware, or any other hypervisor software.

Installing Vagrant (2 Options)

Install Vagrant with apt-get

You have two options to install Vagrant You can run apt-get install command in Ubuntu Linux or download the binary package from Vagrants website.

To Install Vagrant with the apt-get install command use command:

sudo apt install vagrant

The system should download and install the software.

Install Vagrant With the Binary Package

Sometimes, the version of the software in the official repositories is not as recent as on the developer’s website. If you’d rather make sure you’re running the latest version of Vagrant, open a web browser to https://www.vagrantup.com/downloads.html.

Since Ubuntu is a Debian-based operating system, choose either the 32-bit or 64-bit link under the Debian heading.

Alternately, if you know the version of Vagrant you want to download, enter the following in a terminal window:

sudo wget https://releases.hashicorp.com/vagrant/2.2.2/vagrant_2.2.2_x86_64.deb

Then you can install the package using the following command:

sudo dpkg –i vagrant_2.2.2_x86_64.deb

Note: This version 2.2.2 is current as of the writing of this article. You can find the latest version by checking the developer’s download page.

Verify Vagrant Installation

In a terminal window, enter the following:

vagrant ––version

The system should display the current version Vagrant installed on your system.

Deploying Vagrant On Ubuntu 18.04

Now that you have installed Vagrant, let’s create a development environment.

1. Create a new directory to store the virtual operating system you’re going to create:

sudo mkdir ~/vagrant-ubuntu

cd ~/vagrant-ubuntu

2. Download and install your operating system (Vagrant Box) of choice. For example, use this command to install the Trusty Tahr 64-bit system:

sudo vagrant init ubuntu/trusty64

Using the init command loads the virtual operating system. It also creates a default basic configuration file. This is called the Vagrantfile, and it’s located in the same directory you just created. This file can be edited and copied to other systems.

3. Now use the vagrant up command to create and configure the virtual machine according to the Vagrantfile.

The system should show the default SSH address, username, and authentication method for the new virtual machine.

4. To connect to the virtual machine by SSH, enter the following:

vagrant ssh

You can now work in the new virtual environment.

Other Vagrant Commands

To stop the virtual machine:

vagrant halt

To delete the virtual machine, use the command:

vagrant destroy

This will also destroy any work you have done inside the virtual OS.

To manually create a Vagrantfile type in the following command:

touch vagrantfile

This will create a blank Vagrantfile as a placeholder. The vagrant up command should then launch a default virtual environment. A text editor can also be used to edit the Vagrantfile.

Conclusion

Now, you know how to install and configure Vagrant on your Ubuntu system. You should have a functioning Ubuntu virtual machine managed through Vagrant.