Saturday, December 28, 2024
Google search engine
HomeGuest BlogsHow to Install, Deploy, and Uninstall Vagrant on Ubuntu 22.04

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

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 UbuntuHow 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 outputsudo 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 outputsudo apt install Vagrant terminal output

Verify the installation with:

vagrant --version
Vagrant version terminal outputVagrant 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 outputwget 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 outputdpkg -i terminal output

3. Verify the version:

vagrant --version
Vagrant version 2.3.7. terminal outputVagrant 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 outputVagrant 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 outputvagrant 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 outputvagrant 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 outputvagrant 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 VirtualBoxVagrant 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 outputvagrant halt terminal output

To delete the virtual machine, execute:

vagrant destroy
vagrant destroy terminal outputvagrant destroy terminal output

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

vagrant status:

vagrant status terminal outputvagrant 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 outputsudo apt remove vagrant terminal output

Use autoremove to remove both the software and its dependencies:

sudo apt autoremove vagrant
sudo apt autoremove vagrant terminal outputsudo 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 outputsudo 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

RELATED ARTICLES

Most Popular

Recent Comments