How to install Vagrant on Ubuntu 20.04

s2 0

Tramp
is a command line tool for creating and managing virtual machines.

By default, Vagrant can provision machines in addition to VirtualBox, Hyper-V and Docker. Other providers such as Libvirt (KVM), VMware and AWS can be installed via the Vagrant plug-in system.

Vagrant is typically used by developers to set up a development environment that works across multiple operating systems.

This article describes how to install Vagrant on an Ubuntu 20.04 computer. We use VirtualBox, the standard provider for Vagrant.

Install Vagrant on Ubuntu

We will deploy the virtual machines on VirtualBox.

If VirtualBox is not installed on your system, you can install it by running:

sudo apt updatesudo apt install virtualbox

The Vagrant package available in Ubuntu’s repositories is not updated regularly. We will download and install the latest version of Vagrant from the official Vagrant website.

At the time of this writing, the latest stable release of Vagrant is version 2.2.9. Visit the Vagrant download page
to see if a new version of Vagrant is available.

Load the Vagrant package with. down wget
:

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

After the file is downloaded, install it by typing:

sudo apt install ./vagrant_2.2.9_x86_64.deb

To verify that the installation was successful, run the following command which will print the Vagrant version:

vagrant --version

The output should look something like this:

Vagrant 2.2.9

Getting started with Vagrant

Creating a Vagrant project is as easy as setting up the project root directory and defining a Vagrant file.

Run the following commands to create the directory and cd into it:

mkdir ~/my-vagrant-projectcd ~/my-vagrant-project

Next, initialize a new Vagrantfile with the vagrant init Command followed by the field you want to use.

Boxes are the package format for the Vagrant environments and are provider-specific. A list of the publicly available Vagrant boxes can be found on the Vagabond Box Catalog
Page.

In this example we are using the centos/8 Crate:

vagrant init centos/8
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.

Vagrantfile is a Ruby file that describes how to configure and provision the virtual machine. You can open it Vagrantfile
, read the comments and make adjustments according to your needs.

Run the vagrant up Command to create and configure the virtual machine as specified in the Vagrantfile:

vagrant up
==> 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-vagrant-project/ => /vagrant

Vagrant mounts the project directory /vagrant in the virtual machine. This allows you to work on your project files on your host computer.

To SSH the virtual machine, do the following:

vagrant ssh

You can stop the virtual machine with the following command:

vagrant halt

Enter the following to destroy all resources created during the creation of the machine:

vagrant destroy

diploma

We showed you how to install Vagrant on Ubuntu 20.04 and create a simple Vagrant project.

For more information on Vagrant, visit the official Hiking documentation
Page.

If you have any questions please leave a comment below.