How to Install Vagrant on Ubuntu 20.04

How to Install Vagrant on Ubuntu 20.04

   

The ease of creating and destroying the virtual machine instances on the fly makes it more prominent in many production environments. Because of the popularity of VMs, in this article, I am going to explain how to install Vagrant on Ubuntu 20.04.

What is Vagrant?

If you are a first time user, then you might want to know what Vagrant is, in the first place?

Vagrant is a command-line tool built to create and manage virtual machines. Out of the box, Vagrant supports VirtualBox, Hyper-V, and Docker. But, Vagrant has the ability to manage other types of machines as well, such as KVM (libvirt), VMware and AWS through Vagrant plugin system.

It has pre-configured boxes (the OS images, in simple word) a vagrantfile to configure a VM. More on this is out of the scope of this page but I will cover those in a vagrant specific page.

How to Install Vagrant on Ubuntu 20.04?

I will show you by installing a CentOS 8 on top of Virtualbox. So, make sure that you have already installed VirtualBox on Ubuntu 20.04.

Vagrant can be installed from the Ubuntu’s repository but that is not recommended as has a very old version.
So, we will be downloading the latest Vagrant from the official download page.

Download Vagrant:

As of writing this guide Vagrant 2.2.9 was the latest. But you make sure to visit the above download page to get the latest one!

Download the latest Vagrant using wget or curl command:

wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb

(or)

curl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb

Install Vagrant:

Once the file is downloaded, execute the below command to install it:

sudo apt install ./vagrant_2.2.9_x86_64.deb

Verify Vagrant Installation

To verify if it is installed successfully, execute the below command:

vagrant --version

Output:

Vagrant 2.2.9

Install Linux Distro using Vagrant on Ubuntu 20.04

It is recommended that you create a project directory and then work on that directory for any Vagrant installations etc.

Execute the below commands to create and cd to the project directory:

mkdir ~/vagrant-projects
cd ~/vagrant-projects

Initialize Vagrantfile

Now, initialize a vagrantfile with a specific box that you want to use.

Usually, Boxes are related to distro. VM and are provider specific. You can browse through all available Vagrant boxes.

In this demo I will use the CentOS 7 box to install:

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.

You can open the Vagrantfile, and re-configure it as per your project needs.

Now, execute the below command to create and configure the virtual machine:

vagrant up

Output:

==> default: Configuring and enabling network interfaces...
    default: SSH address: 192.168.10.56:22
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /home/cpqlinux/Vagrant/vagrant-projects/ => /vagrant

Vagrant mounts the project directory on the host machine at /vagrant in the newly created virtual machine. So, you do not need to create a shared directory for virtual machines to work on your VM project’s files on your host machine.
==> default: Rsyncing folder: /home/cpqlinux/Vagrant/vagrant-projects/ => /vagrant

Other Useful Vagrant commands

Execute the below to login to the VM via SSH:

vagrant ssh

To shutdown the virtual machine execute the below command:

vagrant halt

To destroy all resources created during the creation of the machine, execute below command:

vagrant destroy

That’s on installing Vagrant on Ubuntu 20.04 that helps in creating, managing and destroying virtual machines. For more information, you can always visit the official Vagrant docs page.

Previous How to Install ADB Fastboot on Linux
Next How To Check System Hardware Information In Ubuntu 20.04 LTS?

About author

Sibananda Sahu
Sibananda Sahu 136 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

Installation 0 Comments

How To Install Android Studio on Ubuntu?

This post was last updated on June 23rd, 2020 at 08:05 pmAndroid studio is the official IDE for android application development by Google. It is based on JetBrains’ IntelliJ IDEA

Installation 0 Comments

Installing Linux on a Compaq PL4500

This post was last updated on June 1st, 2020 at 12:07 pm The PL4500 is about the only server I can think of that Linux cannot use the embedded SCSI

Installation 0 Comments

Setting up PXE Server

This post was last updated on July 9th, 2020 at 03:42 pmRed Hat 8.0 PXE server, etc. on PL2500 Red Hat 8.0 – default custom install First let’s set up

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply