Vagrant is a an open-source tool for building and managing virtual machines. Generally, Vagrant is used by developers to set up a development environment that works across multiple operating systems. In this tutorial, we will show you how to install Vagrant on Ubuntu 20.04 system.
- Virtualbox should installed on your Ubuntu 20.04 system.
- You must logged in as root or user with sudo privileges.
Installing Vagrant on Ubuntu
By default Ubuntu repositories includes Vagrant package, but it is not regularly updated. So we will download and install latest version of Vagrant from the official Vagrant website.
Currently, at the time of writing this tutorial, the latest version of Vagrant is
2.2.9. It always good to check latest version at Vagrant download page before starting installation.
Run the below command to download Vagrant using curl:
curl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb
Once the download complete, execute below command to install it:
sudo apt install ./vagrant_2.2.9_x86_64.deb
You can verify the installation by typing:
It should show output as following:
Using Vagrant on Ubuntu
It’s very simple to create a Vagrant project. To define a root directory run below command to create the directory and navigate into it with:
After that, we need to initialize a new Vagrantfile using the
vagrant init command, followed by the box you want to use.
Get the list of publicly available Vagrant Boxes on the Vagrant box catalog page.
For demostration we will use the
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 file describes the type of machine required and how to configure. You can edit the Vagrantfile and do changes as your needs.
Now, run the
vagrant up command to create and configure the virtual machine as specified in the Vagrantfile:
==> default: Configuring and enabling network interfaces... default: SSH address: 22.214.171.124:22 default: SSH username: vagrant default: SSH auth method: private key ==> default: Rsyncing folder: /home/tecnstuff/Vagrant/vagrant-test/ => /vagrant
Vagrant mounts the project directory at
/vagrant in the virtual machine. This allows you to work on your project’s files on your host machine.
To ssh into the virtual machine, run:
Run the below command to login to VM using SSH:
To shutdown the virtual machine execute the below command:
To destroy all resources created during the creation of the machine, enter:
This article shown you how to install Vagrant on Ubuntu 20.04 and use of Vagrant project. To know more about Vagrant visit, the official Vagrant documentation page.
If you have any questions, please leave a comment below.