Setup vagrant on Linux/Ubuntu
Shoaib Akbar
Posted on February 23, 2020
A complete guide to setup vagrant on Ubuntu 18.04
Install VirtualBox
Start by importing GPG keys of the Oracle Virtualbox repository:
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
Both commands should output OK which means that keys are successfully imported and packages from this repository are trusted.
Next add virtual box APT repository:
sudo add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"
$(lsb_release -cs) will print the Ubuntu codename. For example, if you have Ubuntu version 18.04 the command will print bionic.
If you get an error message saying add-apt-repository command not found then you need to install the software-properties-common package.
Once the Virtualbox repository is enabled, update the apt package list and install the latest version of Virtualbox:
sudo apt update
sudo apt install virtualbox-6.0
Now Virtualbox is installed on your Ubuntu system, start:
virtualbox
Installing Vagrant
update package list:
sudo apt update
Download the Vagrant package:
curl -O https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.deb
NOTE
if curl is not installed :
sudo apt install curl
Now try to download the Vagrant package again
Once the .deb file is downloaded, install it:
sudo apt install ./vagrant_2.2.6_x86_64.deb
Verify Vagrant installation:
vagrant --version
The output should be similar to
Vagrant 2.2.6
Getting Started with Vagrant
Now Vagrant is installed on your Ubuntu system let's create a development environment.
The first step is to create root directory for project which will contain Vagrantfile file. Vagrantfile is a Ruby file that contain configurations and provision the virtual machine.
mkdir ~/my-first-vagrant-project
cd ~/my-first-vagrant-project
Next initialize a new Vagrantfile (will create vagrant file):
vagrant init
and specify the box you want to use.
(You can search other boxes on this link https://app.vagrantup.com/boxes/search we’ll use ubuntu/trusty64)
'vagrant init ubuntu/trusty64`
Now create and configure the virtual machine as specified in the Vagrantfile:
vagrant up
Next update changes in Vagrantfile:
vagrant provision
Next reload vagrant and virtual box:
vagrant reload
To ssh into the virtual machine:
vagrant ssh
Can stop the virtual machine:
vagrant halt
Can destroys all resources(be careful):
vagrant destroy
Keep Learning!
Posted on February 23, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.