In this tutorial we are going to learn how to install Vagrant on Ubuntu 18.04. We will also install and configure its prerequisites. Vagrant is an open source tool that helps in building and managing virtual environments. In a software development company, it is always difficult and requires constant monitoring in the maintenance of virtual environments. This is where Vagrant comes to your rescue as you can set up a virtual environment in minutes to mimic your production environment for the testing the latest release of code. Vagrant uses Virtualbox to create and maintain virtual environments. Even though there is a lot of virtual software like Docker, VMware etc. Vagrant has gone a step ahead to provide an easy way to create and reproduce multiple virtual machines within minutes.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 LTS Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install Vagrant on Ubuntu 18.04
Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:
apt-get update -y apt-get upgrade -y
Step 2. Install VirtualBox.
Installing VirtualBox using following command:
sudo apt-get install virtualbox
Step 3. Install Vagrant on Ubuntu 18.04 Bionic Beaver.
Now install Vagrant in your ubuntu box using the following command:
sudo apt-get install vagrant
Verify Vagrant version:
$ vagrant Usage: vagrant [options] <command> [<args>] -v, --version Print the version and exit. -h, --help Print this help. Common commands: box manages boxes: installation, removal, etc. connect connect to a remotely shared Vagrant environment destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login log in to HashiCorp's Vagrant Cloud package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine share share your Vagrant environment with anyone in the world snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment validate validates the Vagrantfile version prints current and latest Vagrant version For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`.
Step 4.Deploying the Vagrant system.
We can find Vagrant Boxes on the Vagrant Cloud.
ubuntu/xenial64 is one of the most popular box (machine), which has nearly 30 million installs. So we will install this box:
vagrant box add ubuntu/xenial64
Now initialize the vagrant box using the following command:
vagrant init ubuntu/xenial64
Finally run the following command to start your box:
Now connect to you newly created machine via ssh using following command:
Congratulation’s! You have successfully install and configured Vagrant on your Ubuntu 18.04 server. Thanks for using this tutorial installing Vagrant on Ubuntu 18.04 LTS (Bionic Beaver) system.