How to Install, Deploy, and Uninstall Vagrant on Ubuntu 22.04

September 4, 2023

Introduction

Vagrant is a software application that uses virtualization technology to create an operating system environment. From the CLI, Vagrant loads, prepares, and launches a virtual VagrantBox environment.

This guide will show you how to install Vagrant on Ubuntu 22.04.

How to install Vagrant on Ubuntu

Prerequisites

Install VirtualBox

To install Vagrant, first get a cloud (virtualization) hypervisor. Any virtual machine, such as KVMDocker, VMware, or VirtualBox, is able to fulfill this purpose. This example uses VirtualBox.

VirtualBox is a virtualization tool that allows users to create and manipulate several OSs as virtual machines. Since Vagrant creates virtual operating systems, it needs a tool like VirtualBox to manage them. 

To install VirtualBox, run:

sudo apt install virtualbox -y
sudo apt install virtualbox terminal output

Install Vagrant

There are several ways to install Vagrant on Ubuntu 22.04. The following text explains each option. 

Note: Run sudo apt update && sudo apt upgrade before installation.

Option 1: Install Vagrant with apt

The simplest way to install Vagrant is with the apt package manager. Run the following:

sudo apt install vagrant
sudo apt install Vagrant terminal output

Verify the installation with:

vagrant --version
Vagrant version terminal output

Option 2: Install Vagrant With the Binary Package 

Sometimes, the software version in the official repositories is not as recent as on the developer's website. Find the latest version by checking the developer's download page.

At the time of the writing of this article, the Vagrant version is 2.3.7. To download and install the latest version:

1. Run the wget command:

wget https://releases.hashicorp.com/vagrant/2.3.7/vagrant_2.3.7-1_amd64.deb
wget terminal output

The command downloads the 2.3.7-1_amd64.deb package. 

Note: Before Vagrant 2.3.0, the Debian package file was named x86_64.deb. This changed to amd64.deb starting with Vagrant 2.3.0. This aligns with the commonly used architecture label amd64 for 64-bit systems.

2. Navigate to the directory Vagrant is downloaded in and run dpkg:

sudo dpkg -i vagrant_2.3.7-1_amd64.deb
dpkg -i terminal output

3. Verify the version:

vagrant --version
Vagrant version 2.3.7. terminal output

Deploy Vagrant On Ubuntu 22.04

The next part is to deploy Vagrant. Follow these steps:

1. Create a project directory using the following syntax:

mkdir ~/project_name

For example, create a vagrant-ubuntu project

mkdir ~/vagrant-ubuntu

The command has no output

2. Use cd to navigate to the created directory:

cd ~/vagrant-ubuntu
Vagrant CD command terminal output

The command has no output but shows the terminal is working from the new directory.

3. Visit the Vagrant official website and choose a VagrantBox. For example, select and copy the ubuntu/trusty64 box name.

4. Initialize the process with the init command:

vagrant init ubuntu/trusty64
vagrant init ubuntu terminal output

The init command initializes a Vagrant project. It also creates a Vagrant configuration file, Vagrantfile, which contains the ubuntu/trusty64 box configuration.

5. Next, create and configure the virtual machine according to the Vagrantfile with:

vagrant up
vagrant up terminal output

The command downloads the box (if not already downloaded) and creates a virtual machine based on it. It appends the selected box to the VirtualBox environment. The output shows the new virtual machine's default SSH address, username, and authentication method.

6. To SSH into a running Vagrant virtual machine, run:

vagrant ssh
vagrant ssh terminal output

The command establishes an SSH session into the running virtual machine, giving users access to the shell.

 Another option is to access the VirtualBox on the system.

Vagrant in VirtualBox

Other Vagrant Commands

Once connected, multiple commands work with Vagrant

For instance, to stop the virtual machine, run:

vagrant halt
vagrant halt terminal output

To delete the virtual machine, execute:

vagrant destroy
vagrant destroy terminal output

The command destroys any work inside the virtual OS. To verify the success, run:

vagrant status:

vagrant status terminal output

Note: To learn what else Vagrant does, check our complete guide to starting with Vagrant.

Uninstall Vagrant on Ubuntu 22.04

To uninstall Vagrant, run the remove command:

sudo apt remove vagrant
sudo apt remove vagrant terminal output

Use autoremove to remove both the software and its dependencies:

sudo apt autoremove vagrant
sudo apt autoremove vagrant terminal output

To remove Vagrant, its dependencies, and configuration files, use autoremove and purge:

sudo apt autoremove --purge vagrant
sudo apt autoremove purge vagrant terminal output

Conclusion

After reading this article, you know how to install and configure Vagrant on your Ubuntu system.

Next, learn how to do the same on CentOS.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Vagrant Tutorial: Everything a Beginner Needs To Know
April 17, 2019

Vagrant is a tool for configuring and deploying an exact image of a virtual operating system. It is often ...
Read more
How to Install VMware Workstation on Ubuntu
March 21, 2024

This easy tutorial shows you how to install VMware Workstation Pro on Ubuntu. Running a virtual machine (VM) ...
Read more
How to Install Vagrant on CentOS 7
March 24, 2019

Vagrant is a software package that creates a standardized operating environment. It does this using ...
Read more
What is Server Virtualization? Definition and How it Works
February 24, 2019

A virtualized server allows one piece of hardware to be used as multiple virtual servers. Learn about Server ...
Read more