How to Install Vagrant on Ubuntu 20.04

Jun 10
16:12

2021

HItesh Jethva

HItesh Jethva

  • Share this article on Facebook
  • Share this article on Twitter
  • Share this article on Linkedin

In this post, we will show you how to install Vagrant on Ubuntu 20.04 desktop.

mediaimage

Vagrant is a free and open-source command-line utility written in Ruby and actively developed by HashiCorp.It is used to create and manage virtual machines. Generally,How to Install Vagrant on Ubuntu 20.04 Articles it is used by developers to set up a development environment for multiple operating systems. Vagrant has built-in support for VirtualBox, Docker, KVM and Hyper-V.

 

In this tutorial, we will explain how to install Vagrant with VirtualBox on Ubuntu 20.04.

 

    1. Requirements
  • A Ubuntu 20.04 Desktop system.

  • A root password is set on the system.

    1. Create Atlantic.Net Cloud Server

 

First, Login to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system, with at least 4GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

 

Once you are logged into your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

 

apt-get update -y

 

Install VirtualBox

 

In this tutorial, we will use VirtualBox as a provider. So you will need to install the VirtualBox in your system.

 

By default, VirtualBox is available in the Ubuntu 20.04 default repository. You can install it with the following command:

 

apt-get install virtualbox -y

 

Once the VirtualBox is installed, you can proceed to the next step.

 

Install Vagrant

 

By default, the latest version of Vagrant is not available in the Ubuntu 20.04 standard repository. So you will need to download the latest version of Vagrant from the Hashicorp website. You can download it with the following command:

 

wget https://releases.hashicorp.com/vagrant/2.2.10/vagrant_2.2.10_x86_64.deb

 

Once the Vagrant package is downloaded, you will need to install GNUPG2 package in your system. You can install it with the following command:

 

apt-get install gnupg2 -y

 

Once installed, run the following command to install the Vagrant package:

 

dpkg -i vagrant_2.2.10_x86_64.deb

 

Once the vagrant has been installed, you can verify the installed version with the following command:

 

vagrant --version

 

You should get the following output:

 

Vagrant 2.2.10

 

Setup Vagrant Environment

 

First, change the directory to the /mnt and initialize a new Vagrantfile using the vagrant init command with your desired operating system.

 

For example, let's initialize a new Vagrantfile using CentOS 8:

 

cd /mnt

vagrant init centos/8

 

This will generate a vagrantfile for CentOS 8 as shown below:

 

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.

 

Next, run the following command to create a virtual machine for CentOS 8:

 

vagrant up

 

This will download the CentOS 8 ISO and setup an environment for it based on the default configuration.

 

Bringing machine 'default' up with 'virtualbox' provider...

==> default: Box 'centos/8' could not be found. Attempting to find and install...

default: Box Provider: virtualbox

default: Box Version: >= 0

==> default: Loading metadata for box 'centos/8'

default: URL: https://vagrantcloud.com/centos/8

==> default: Adding box 'centos/8' (v1905.1) for provider: virtualbox

default: Downloading: https://vagrantcloud.com/centos/boxes/8/versions/1905.1/providers/virtualbox.box

Download redirected to host: cloud.centos.org

default: Calculating and comparing box checksum...

==> default: Successfully added box 'centos/8' (v1905.1) for 'virtualbox'!

Bringing machine 'default' up with 'virtualbox' provider...

==> default: Checking if box 'centos/8' version '1905.1' is up to date...

==> default: Clearing any previously set forwarded ports...

==> default: Fixed port collision for 22 => 2222. Now on port 2200.

==> default: Clearing any previously set network interfaces...

==> default: Preparing network interfaces based on configuration...

default: Adapter 1: nat

==> default: Forwarding ports...

default: 22 (guest) => 2200 (host) (adapter 1)

==> default: Booting VM...

==> default: Waiting for machine to boot. This may take a few minutes...

default: SSH address: 127.0.0.1:2200

default: SSH username: vagrant

default: SSH auth method: private key

 

Once the setup is completed, you can run the following command to connect your newly created virtual machine:

 

vagrant ssh

 

To shut down the virtual machine, run the following command:

 

vagrant halt

 

You can destroy all resources created during the creation of the machine by running the following command:

 

vagrant destroy

 

Conclusion

 

In this tutorial, you learned how to install Vagrant on Ubuntu 20.04. You also learned how to create and start a virtual machine with Vagrant. For more information, visit the Vagrant official documentation page.

 

If you would like to host your application on the cloud server then I would recommend trying Atlantic.net Cloud and get started with one full year of free VPS hosting in the cloud!