Vagrant is an automation software used for building and managing virtual machines easily.
Vagrant gives a developer a disposable consistent environment for developing and managing any scripts.
In this guide you are going to learn how to install Vagrant on Ubuntu 20.04.
Install Virtual Box
Start by updating the software packages to the latest version.
sudo apt update
Here we will use VirtualBox on which we use Vagrant to provision virtual machines.
You can install VirtualBox using the following command.
sudo apt install virtualbox
This will take sometime to complete the installation. Once the installation is completed you can proceed to install Vagrant.
Install Vagrant
To install Vagrant you need to download the latest version of .deb
file from the vagrant downloads page.
Click the Debian tab and copy the download link and use curl
or wget
command to download the Vagrant package.
wget https://releases.hashicorp.com/vagrant/2.2.14/vagrant_2.2.14_x86_64.deb
Once the file is downloaded you can install Vagrant.
sudo apt install ./vagrant_2.2.14_x86_64.deb
Now Vagrant will get installed and you can verify the installation using the below command.
vagrant -v
You will receive an output similar to the one below.
Output
Vagrant 2.2.14
Setup a New Virtual Machine
Now you can setup a new machine using your favorite OS. Here we will use Debian 10 image.
Create a root directory for your project and setup a Vagrantfile.
sudo mkdir ~/debian-box
cd ~/debian-box
You can use the init
command followed by the box name to create the Vagrantfile for you.
You can choose your own boxes from the official catalog.
vagrant init generic/debian10
Now a new Vagrantfile will get created automatically and placed inside your current directory.
You can use the up command to provision a virtual machine using the configurations in the Vagrantfile.
vagrant up
Once the creation is completed you will have a new virtual machine running on top of Virtual Box using Vagrant.
Additional commands
SSH to the the virtual machine.
vagrant ssh
Stop virtual machine.
vagrant halt
Remove virtual machine.
vagrant destroy
Conclusion
Now you have learned how to install Vagrant and create a new virtual machine with Debian 10 image.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.