Oct 9, 2023 4 min read

How to Install Vagrant on Ubuntu 20.04

Install Vagrant on Ubuntu 20.04 with our step-by-step tutorial. It is a command-line tool for building and managing virtual machine environments.

Install Vagrant on Ubuntu 20.04
Table of Contents

Introduction

Before, we begin talking about how to install Vagrant on Ubuntu 20.04. Let's first understand - What is Vagrant?

Vagrant is a command-line tool for building and managing virtual machine environments. By default, Vagrant can provision machines on top of VirtualBox, Hyper-V, and Docker too. Other providers like Libvirt (KVM) and VMware can be installed through the Vagrant plugin system. Moreover, it is useful for developers to set up a development environment that perfectly matches the production environment.

In this tutorial, you will Install Vagrant on Ubuntu 20.04. We will also address a few FAQs related to the Vagrant.

Advantages of Vagrant

  1. Easy environment setup: Vagrant simplifies the provisioning process for developers, ensuring consistent development environments across different machines.
  2. Portability: Vagrant allows developers to create and share portable development environments, enabling easy collaboration and reducing compatibility issues.
  3. Cost-effective: Using Vagrant eliminates the need for multiple physical/virtual machines, reducing hardware costs and optimizing resource utilization.
  4. Isolation: Vagrant provides isolated environments, enabling developers to experiment without affecting the host machine or other projects.
  5. Flexibility: Vagrant supports multiple platforms and integrates seamlessly with popular virtualization technologies, offering flexibility and adaptability to developers.

Prerequisites

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 -y

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

Step 2 - Install Vagrant

Method 1: Using the Deb file

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.3.7. 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:

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

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

sudo apt install ./vagrant_2.3.7-1_amd64.deb

Method 2: Using Source list.

1) Import the gpg keys:

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

2) Add the source list:

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

3) Install vagrant:

sudo apt update && sudo apt install vagrant -y

Step 3 - Verify the Vagrant installation

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

vagrant --version

The output will look like this:

Output

Vagrant 2.3.7

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, which 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 will allow 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 the machine:

vagrant destroy

FAQs to Install Vagrant on Ubuntu 20.04

Can I use Vagrant with other virtualization platforms?

es, Vagrant supports various virtualization platforms such as VirtualBox, VMware, and Hyper-V. Install the desired provider before using it with Vagrant.

Are there any system requirements for using Vagrant?

Vagrant has minimal system requirements. Ensure you have enough disk space, memory, and a supported virtualization platform installed on your machine.

How do I create a Vagrantfile for my project?

In your project's root directory, run vagrant init in the terminal. This will create a basic Vagrantfile that you can customize according to your needs.

How do I start a Vagrant virtual machine?

Use the command vagrant up in the terminal while inside your project's directory. Vagrant will download the base image and start the virtual machine.

How do I suspend, halt, or destroy a Vagrant virtual machine?

To suspend the virtual machine, use vagrant suspend. For halting, use vagrant halt, and for destroying, use vagrant destroy.

Can I share my Vagrant environment with others?

Yes, you can share your Vagrant environment using the Vagrant Cloud service, sharing the Vagrantfile and base image with collaborators.

How do I update Vagrant and its plugins?

To update Vagrant, run sudo apt-get update && sudo apt-get upgrade vagrant. For updating installed plugins, use vagrant plugin update.

Conclusion

We hope this detailed guide helped you understand how to install Vagrant on Ubuntu 20.04. To learn more about Vagrant installation on Ubuntu 20.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.