Sep 9, 2023 4 min read

How to Install Vagrant on Ubuntu 22.04

Install Vagrant on Ubuntu 22.04 with our step-by-step tutorial. Vagrant is an open-source tool for managing virtual development environments.

Install Vagrant on Ubuntu 22.04
Table of Contents

Introduction

Before, we begin talking about How to Install Vagrant on Ubuntu 22.04. Let's first understand - What is Vagrant?

Vagrant is a powerful open-source tool used in software development to create and manage virtual development environments. It simplifies the setup process by automating the configuration of virtual machines, making it easier for developers to collaborate and work on projects.

With Vagrant, you can easily reproduce and share development environments, ensuring consistency across different machines. This handy tool streamlines the deployment process, enabling developers to focus on coding rather than dealing with complex environment setup.

In this tutorial, you will Install Vagrant on the Ubuntu 22.04. We will also address a few FAQs on how to install Vagrant on Ubuntu 22.04.

Advantages of Vagrant

  1. Streamlined Development: Vagrant simplifies environment setup, allowing developers to quickly create and share consistent development environments.
  2. Collaboration: Vagrant facilitates collaboration by ensuring all team members work with the same development environment.
  3. Portability: With Vagrant, you can easily move your development environment across different machines and operating systems.
  4. Automation: Vagrant automates the setup and configuration of virtual machines, saving time and reducing errors.
  5. Flexibility: Vagrant supports various virtualization providers and configuration options, providing flexibility to developers for their specific needs.

Prerequisites to Install Vagrant on Ubuntu 22.04

1) A user with sudo privileges.

2) A terminal window/command line (Ctrl-Alt-T).

Step 1 – Install the VirtualBox

1) You will provision the machines on top of VirtualBox. So, first install the VirtualBox package. It is available in the Ubuntu’s repositories:

sudo apt install virtualbox

You can also install the latest VirtualBox version from the Oracle repositories.

Step 2 – Install Vagrant

1) The Vagrant package, available in Ubuntu’s repositories, is quite out-of-date. Now, you will need to download and install the latest version of Vagrant. Do it from the official Vagrant site. Here, the latest stable version of Vagrant is version 2.2.6. Further, check the Vagrant Download page for a new version, if available. Then, start by updating the package list using the following command:

sudo apt update

2) After that, download the Vagrant package. You will use the below curl command:

curl -O https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.deb

3) After, the .deb file is download, install it by typing:

sudo apt install ./vagrant_2.2.6_x86_64.deb

Step 3 – Verify the Vagrant installation

1) In order to verify if the installation is successful. Run the below command, printing the Vagrant version:

vagrant --version

The output will look like this:

Output

Vagrant 2.2.6

Step 4 – Starting with the Vagrant

1) Now, you will create a development environment. Firstly, you need to create a directory which will be the project root directory and will hold the Vagrantfile file, that is a Ruby file. It describes how to configure as well as provides the virtual machine.

2) Then, create a project directory and switch to it using the following command:

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

3) Proceed to initialize a new Vagrantfile. Do it by using the vagrant init command. Moreover, specify the box you want to use.

The Boxes are the package format for the Vagrant environments. They are actually provider-specific. You will find a list of publicly available Vagrant Boxes on the Vagrant box catalog page.

4) In this example, you will use the centos/7 box. Next, run the below command to initialize a new Vagrantfile:

vagrant init centos/7
Output

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.

5) You will now open the Vagrantfile. Read the comments and make adjustments as per your needs.

6) After that, run the vagrant up command. It will create and configure the virtual machine, as specified in Vagrantfile:

vagrant up
Output
==> default: Configuring and enabling network interfaces...
    default: SSH address: 192.168.121.74:22
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /home/linuxize/Vagrant/my-first-vagrant-project/ => /vagrant

7) Vagrant further mounts the project directory at /vagrant in the virtual machine. It allows you to work on the project’s files on the host machine. So, to ssh into the virtual machine, run:

vagrant ssh

8) To stop the virtual machine, run:

vagrant halt

The above command will stop the machine if it is running. Also, will destroy all resources made during the creation of machine:

vagrant destroy

FAQs to Install Vagrant on Ubuntu 22.04

Can I use Vagrant without VirtualBox?

No, VirtualBox is one of the supported virtualization providers for Vagrant. It is required to create and manage virtual machines.

How can I create a new Vagrant environment?

Use the vagrant init command to initialize a new Vagrant environment. Customize the Vagrantfile according to your requirements.

How do I start a Vagrant virtual machine?

Navigate to the project directory and run vagrant up in the terminal. Vagrant will create and start the virtual machine based on the Vagrantfile.

How can I SSH into a Vagrant virtual machine?

Use the command vagrant ssh in the terminal while inside the project directory. This will establish an SSH connection to the virtual machine.

How do I suspend or halt a Vagrant virtual machine?

Run vagrant suspend to save the current state and temporarily stop the virtual machine. Use vagrant halt to shut down the virtual machine.

Can I share my Vagrant environment with others?

Yes, Vagrant allows you to package and share your development environment using Vagrant boxes or tools like Vagrant Cloud.

How do I uninstall Vagrant from Ubuntu 22.04?

To uninstall Vagrant, run sudo dpkg -r vagrant in the terminal. This will remove Vagrant from your Ubuntu 22.04 system.

Conclusion

We hope this detailed tutorial helped you to install Vagrant on Ubuntu 22.04. To learn more about Vagrant installation on Ubuntu 22.04 server, check out the official Vagrant documentation.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.