Cyberithub

How to Install Vagrant on Ubuntu 20.04 LTS [Step by Step]

Advertisements

In this article, I will take you through the steps to install Vagrant on Ubuntu 20.04 LTS. Vagrant is an open source software that has been built in the Ruby Language. It is incredibly popular in building virtual environments quickly due to its easy integration with multiple virtual environments providers like VirtualBox, VMware and Docker. It helps in simplifying the workflow and reduce the workload necessary to run and operate VMs on your Systems. Vagrant provides simple set of commands to accomplish complex tasks.

What is Provider

Provider is a software virtualization solution such as VirtualBox, VMWare Fusion, or VMWare Workstation in Vagrant Ecosystem.

Advertisements

What is Vagrantfile

A Vagrantfile is a configuration file that uses the Ruby programming language syntax. Vagrant uses this file to understand what action needs to be taken when a command is sent by the user from the terminal.

How to Install Vagrant on Ubuntu 20.04 LTS [Step by Step]

How to Install Vagrant on Ubuntu 20.04 LTS

Also Read: How to Create a Large File in Linux [4 Simple and Easy Methods]

Advertisements

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

Advertisements

c) You should have apt or apt-get utility available in your Server.

 

Step 2: Update Your Server

Before going through the steps to install vagrant, it is highly recommended to check for any updates from all the configured repositories using apt update or apt-get update command as shown below. This will also update the package cache with any package information available in any of the configured repositories.

Advertisements
root@localhost:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:3 http://ppa.launchpad.net/hluk/copyq/ubuntu focal InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:5 https://artifacts.elastic.co/packages/oss-7.x/apt stable InRelease
Get:6 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Ign:7 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 InRelease
Hit:8 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release
Get:10 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,090 B]
Hit:11 https://download.docker.com/linux/ubuntu focal InRelease

 

Step 3: Install Provider

Vagrant needs a provider to create VM. VirtualBox is the default provider for vagrant so to install this you need to run apt install virtualbox command as shown below.

root@localhost:~# apt install virtualbox
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
i965-va-driver intel-media-va-driver kwayland-data kwayland-integration libaacs0 libaom0 libass9 libavcodec58 libavdevice58 libavfilter7 libavformat58
libavresample4 libavutil56 libbdplus0 libbluray2 libbs2b0 libchromaprint1 libcodec2-0.9 libdbusmenu-qt5-2 libdc1394-22 libfam0 libfftw3-double3 libflite1
libgme0 libgsm1 libigdgmm11 libkf5config-bin libkf5config-data libkf5configcore5 libkf5coreaddons-data libkf5coreaddons5 libkf5guiaddons5 libkf5idletime5
libkf5notifications-data libkf5notifications5 libkf5waylandclient5 libkf5windowsystem-data libkf5windowsystem5 liblilv-0-0 libllvm11 libmysofa1 libnorm1
libopenal-data libopenal1 libopenmpt0 libpgm-5.2-0 libpostproc55 libqt5texttospeech5 librubberband2 libsdl2-2.0-0 libserd-0-0 libshine3 libsnappy1v5
libsndio7.0 libsord-0-0 libsratom-0-0 libssh-gcrypt-4 libswresample3 libswscale5 libtie-ixhash-perl libva-drm2 libva-x11-2 libva2 libvdpau1 libvidstab1.1
libx264-155 libx265-179 libxml-xpathengine-perl libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers va-driver-all
vdpau-driver-all
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
dctrl-tools dkms libgsoap-2.8.91 liblzf1 libqt5opengl5 libqt5printsupport5 libsdl1.2debian libvncserver1 virtualbox-dkms virtualbox-qt
Suggested packages:
debtags menu vde2 virtualbox-guest-additions-iso
The following NEW packages will be installed:
dctrl-tools dkms libgsoap-2.8.91 liblzf1 libqt5opengl5 libqt5printsupport5 libsdl1.2debian libvncserver1 virtualbox virtualbox-dkms virtualbox-qt
0 upgraded, 11 newly installed, 0 to remove and 37 not upgraded.
Need to get 44.9 MB of archives.
............................................................

 

Step 4: Download Vagrant

You can go to Vagrant Official website and download the latest version using any of the file transfer utility like wget or curl. Here we are downloading the latest Vagrant Debian package version 2.2.19 by using wget command as shown below. It will download the package under current working path.

root@localhost:~# wget https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.deb
--2021-12-16 07:57:38-- https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.deb
Resolving releases.hashicorp.com (releases.hashicorp.com)... 2a04:4e42:24::439, 151.101.153.183
Connecting to releases.hashicorp.com (releases.hashicorp.com)|2a04:4e42:24::439|:443... failed: Connection timed out.
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.153.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 41472132 (40M) [application/x-debian-package]
Saving to: ‘vagrant_2.2.19_x86_64.deb’

vagrant_2.2.19_x86_64.deb 100%[============================================================================>] 39.55M 18.6MB/s in 2.1s

2021-12-16 07:59:51 (18.6 MB/s) - ‘vagrant_2.2.19_x86_64.deb’ saved [41472132/41472132]

 

Step 5: Install Vagrant

Now you can use apt package manager to install this package. You need to run apt install ./vagrant_2.2.19_x86_64.deb command to start with the Installation.

root@localhost:~# apt install ./vagrant_2.2.19_x86_64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'vagrant' instead of './vagrant_2.2.19_x86_64.deb'
The following packages were automatically installed and are no longer required:
i965-va-driver intel-media-va-driver kwayland-data kwayland-integration libaacs0 libaom0 libass9 libavcodec58 libavdevice58 libavfilter7 libavformat58
libavresample4 libavutil56 libbdplus0 libbluray2 libbs2b0 libchromaprint1 libcodec2-0.9 libdbusmenu-qt5-2 libdc1394-22 libdouble-conversion3 libfam0
libfftw3-double3 libflite1 libgme0 libgsm1 libigdgmm11 libkf5config-bin libkf5config-data libkf5configcore5 libkf5coreaddons-data libkf5coreaddons5
libkf5guiaddons5 libkf5idletime5 libkf5notifications-data libkf5notifications5 libkf5waylandclient5 libkf5windowsystem-data libkf5windowsystem5
liblilv-0-0 libllvm11 libmysofa1 libnorm1 libopenal-data libopenal1 libopenmpt0 libpcre2-16-0 libpgm-5.2-0 libpostproc55 libqt5core5a libqt5dbus5
libqt5gui5 libqt5network5 libqt5qml5 libqt5quick5 libqt5svg5 libqt5texttospeech5 libqt5waylandclient5 libqt5waylandcompositor5 libqt5widgets5
libqt5x11extras5 librubberband2 libsdl2-2.0-0 libserd-0-0 libshine3 libsnappy1v5 libsndio7.0 libsord-0-0 libsratom-0-0 libssh-gcrypt-4 libswresample3
libswscale5 libtie-ixhash-perl libva-drm2 libva-x11-2 libva2 libvdpau1 libvidstab1.1 libx264-155 libx265-179 libxcb-xinerama0 libxcb-xinput0
libxml-xpathengine-perl libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers qt5-gtk-platformtheme qttranslations5-l10n
qtwayland5 va-driver-all vdpau-driver-all
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
vagrant
0 upgraded, 1 newly installed, 0 to remove and 37 not upgraded.
Need to get 0 B/41.5 MB of archives.
..............................................................

 

Step 6: Check Version

If everything goes well, then vagrant will be installed successfully and now you can check the installed version by using vagrant --version command as shown below.

root@localhost:~# vagrant --version
Vagrant 2.2.19

 

Step 7: Initialize Vagrantfile

Next step is to create a VM using vagrant. For that, you need to first initialize the Vagrantfile with the configuration of the VM you want to bring up. For example, here we are going to create Ubuntu VM so to do that we need to first initialize the environment by using vagrant init ubuntu/focal64 command as shown below.

root@localhost:~# vagrant init ubuntu/focal64
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.

 

Step 8: Configure VM

Once Vagrantfile is created, you are now ready to run vagrant up command to create and configure VM using Vagrantfile. This is single most important command as it is the only one which creates Vagrant VMs. Check more on its documentation.

root@localhost:~# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/focal64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/focal64'
default: URL: https://vagrantcloud.com/ubuntu/focal64
==> default: Adding box 'ubuntu/focal64' (v20211026.0.0) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/ubuntu/boxes/focal64/versions/20211026.0.0/providers/virtualbox.box
Download redirected to host: cloud-images.ubuntu.com
==> default: Successfully added box 'ubuntu/focal64' (v20211026.0.0) for 'virtualbox'!
==> default: Importing base box 'ubuntu/focal64'...
==> default: Matching MAC address for NAT networking...

 

Step 9: Connect VM

To connect the default VM, you need to use vagrant ssh command as shown below. If there are multiple nodes running then you can also connect some specific node using vagrant ssh <node_name> command. More on vagrant ssh documentation.

root@localhost:~# vagrant ssh

 

Step 10: Halt VM

When you are not using the VMs then you can also shut it down to save system resources by using vagrant halt command as shown below. If for some reason graceful shutdown fails then you also have the option to forcefully shutdown the machine by using --force flag.

root@localhost:~# vagrant halt
==> default: Attempting graceful shutdown of VM...
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
==> default: Forcing shutdown of VM...

 

Step 11: Destroy VM

In case you are done using all the VMs created by vagrant, you can destroy it by using simple vagrant destroy command as shown below. If you do not want to ask for confirmation before destroying all the resources then you can use --force flag.

root@localhost:~# vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Destroying VM and associated drives...

Leave a Comment