This guide will show you how to install Vagrant on Ubuntu 22.04.
- Ubuntu 22.04 (this tutorial works for version 20.04 as well).
- Sudo privileges.
- VirtualBox installed.
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
There are several ways to install Vagrant on Ubuntu 22.04. The following text explains each option.
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
Verify the installation with:
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:
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
3. Verify the version:
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:
For example, create a vagrant-ubuntu project
The command has no output
2. Use cd to navigate to the created directory:
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
vagrant init ubuntu/trusty64
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:
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:
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.
Other Vagrant Commands
Once connected, multiple commands work with Vagrant
For instance, to stop the virtual machine, run:
To delete the virtual machine, execute:
The command destroys any work inside the virtual OS. To verify the success, run:
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
sudo apt remove vagrant
autoremove to remove both the software and its dependencies:
sudo apt autoremove vagrant
To remove Vagrant, its dependencies, and configuration files, use
sudo apt autoremove --purge vagrant
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.