This post instructs students and new users on how to install and use Vagrant, a tool for building and managing virtual machine environments, on Ubuntu Linux. The tutorial includes steps to install VirtualBox, a virtualization platform, and Vagrant. It also guides on setting up a development environment, creating a new Vagrant file, and using commands for running, stopping, and deleting the virtual machine.
This post shows students and new users steps to install and use Vagrant on Ubuntu Linux Vagrant is a tool for building and managing virtual machine environments via the command line. Out of the box, Vagrant supports VirtualBox, VMware, and AWS and works with other virtualization software providers to provision virtual machines.
Vagrant is great for developers as it isolates machine dependencies and their configurations within a single disposable, consistent environment, so whether you are working on Linux, Mac OS X, or Windows, everyone will be running the same code in the same environment against the same dependencies and configured the same way.
For this post, we’ll be using VirtualBox as our virtualization platform, which is also the default provider for Vagrant.
Also, for students and new users learning Linux, Ubuntu Linux is the easiest place to start learning. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices.
When you’re ready to install and use Vagrant on Ubuntu Linux, follow the steps below.
How to install VirtualBox on Ubuntu
Since we will be using VirtualBox as our provider, let’s go and install it on Ubuntu Linux. You can simply run the apt-get command to install VirtualBox. However, we’re written a detailed post on how to install and configure VirtualBox on Ubuntu.
Read that post instead, then continue below to install Vagrant on Ubuntu Linux.
After reading the post above and installing VirtualBox, continue below.
How to install Vagrant on Ubuntu Linux
At the time of writing this post, the latest stable version of Vagrant is version 2.2.18. You can check the Vagrant Download page to see if a newer version is available.
First, update the Ubuntu package index using the commands below.
sudo apt update
Then download the Vagrant package using the curl command below with the download link to version 2.2.18.
curl -O https://releases.hashicorp.com/vagrant/2.2.18/vagrant_2.2.18_x86_64.deb
Once the .deb file is downloaded, install it by typing:
sudo apt install ./vagrant_2.2.18_x86_64.deb
Now that Vagrant is installed, let’s go and create a development environment on your Ubuntu Linux machine.
The first step is to create a directory to be used as our project directory to hold Vagrant files. The vagrant file is a Ruby file that describes how to configure and provision the virtual machine.
mkdir ~/vagrant-project cd ~/vagrant-project
With your Vagrant project folder created, run the commands below to initialize a new Vagrant file using the vagrant init command and specify the Linux box to use.
For this tutorial, we will be using Ubuntu Linux 20.04 64bit.
vagrant init ubuntu/bionic64
When you run the commands above, you’ll get a similar message with some configuration settings details.
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 Vagrant up command to create and configure the virtual machine as specified in the Vagrantfile:
You should see the Vagrant build process started. It should download the Ubuntu ISO image and set up its environment based on its default configuration settings for Ubuntu 20.04.
Wait for the setup to complete and start using your environment.
To ssh into the virtual machine, run the following:
You can stop the virtual machine with the following command:
To completely delete or destroy the virtual machine, run the commands below:
That should do it!
This post showed you how to install and use Vagrant on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.