Overview

This guide contains instructions on how to install and do basic configuration of Vagrant.

 

Prerequisites

  • Operating System: Ubuntu 18.04
  • Access to a Terminal or Shell Console
  • VirtualBox is installed for this guide. But not required if using Cloud Providers.

 

Installation

01: Open a terminal window

 

02: Make sure that VirtualBox is installed

$ vboxmanage --version

If not yet installed, you can download VirtualBox here first: https://www.virtualbox.org/wiki/Downloads

 

03: Update the package repository

$ sudo apt update

 

04: Install Vagrant from the package manager. Enter y when asked to confirm.

$ sudo apt install vagrant

 

05: Verify that Vagrant has been installed correctly

$ vagrant --version

 

Configuration

Some are basic configuration when using Vagrant with VirtualBox

01: Create a new Vagrant box with an Ubuntu 18.04 OS. The setup will be:

  • Host: Ubuntu 18.04
  • Guest: Ubuntu 18.04 ← This is the Vagrant box we will be creating

 

02: Navigate or create the directory you want to create the box

$ cd ~

$ mkdir geek-ubuntu-1804

$ cd geek-ubuntu-1804

 

03: Initialize the configuration. This will create a Vagrantfile in the current directory.

$ vagrant init ubuntu/bionic64

 

04: Update the Vagrantfile to make the following changes

  • Expose the Guest port 80 to the Host as port 8099
  • Change the RAM to 2 GB
$ nano Vagrantfile

 

Set the content as follows and save the changes.

...
Vagrant.configure("2") do |config|
  …
  config.vm.network "forwarded_port", guest: 80, host: 8099

  …
  config.vm.provider "virtualbox" do |vb|
    …
    vb.memory = "2048"

  end

 

05: Provision the Vagrant box. This might take some time if you are creating a specific OS. But once it has been created, a cache of the OS image is saved locally.

$ vagrant up

 

06: Verify the status of the machine

$ vagrant status

 

07: Check the accessible/exposed ports to the Host.

$ vagrant port

 

08: Access the server using Vagrant SSH.

$ vagrant ssh

 

09: Exit from the SSH session

$ exit

 

Commands

Vagrant commands must be executed in the directory where the box has been initialized (vagrant init)

Destroying the box
vagrant destroy
Viewing the exposed ports
vagrant port
Halt or stop the machine. Equal to shutdown.
vagrant halt
Suspends or pause the machine
vagrant suspend
Resumes the machine (when paused via suspend)
vagrant resume
View the status
vagrant status

 

Previous Google Cloud Next 2019 | Democratizing AI For Industrial Applications
Next PyCon 2019 | One Engineer, an API, and an MVP: Or, how I spent one hour improving hiring data at my company.