Cloud

How to get started with Vagrant on Ubuntu 18.04

Jack Wallen shows you how to get Vagrant up and running on the Ubuntu 18.04 platform, for easy VM deployment and development.

Vagrant is an open source application used for the creation and management of virtual machine (VM) environments. Unlike most other virtual machine tools, Vagrant focuses on the automation of VM deployment, so development time is significantly lowered.

I want to walk you through the process of installing Vagrant on the Ubuntu 18.04 Desktop environment. Once installed, we'll use Vagrant to launch a VM of Ubuntu Linux.

SEE: Cloud migration decision tool (Tech Pro Research)

What you need

All you will need is a working installation of Ubuntu Desktop, version 18.04. Everything else can be found in the standard repositories.

Installing VirtualBox

Because Vagrant depends upon an existing hypervisor, we must first install one. We'll go with VirtualBox. And because we're using a desktop environment, we can simply open Ubuntu Software, search for VirtualBox, and install with a single click. Once that installation is complete, reboot the desktop, and you're ready to install Vagrant.

Installing Vagrant

Vagrant (and all of its dependencies) can be installed with a single command. Open a terminal and issue:

sudo apt-get install vagrant -y

When that installation finishes, it's time to test our Vagrant system. Do note, if you've installed version 5.2 of VirtualBox, you'll need to download the proper installer for the latest version of from the Vagrant Download page (as VirtualBox 5.2 isn't supported by the version of Vagrant found in the standard repositories) and install with the command:

sudo dpkg -i vagrant*.deb

Deploying a VM

As I mentioned, I'll demonstrate deploying a generic Ubuntu 18.04 VM. To do this, go back to the terminal window and issue the following command to download the necessary image:

vagrant box add generic/ubuntu1804

You will be prompted to select the hypervisor provider (Figure A). Since we're working with VirtualBox, type 4 and hit Enter.

Figure A

Figure A

Selecting a hypervisor for Vagrant.


When the image download is complete, Vagrant will inform you of its success. Next create a new directory for the VM with the command:

mdkir ~/ubuntu1804

Change into that newly created directory with the command:

cd ~/ubuntu1804

Create a new Vagrant file with the command:

nano Vagrantfile

Copy the following contents to the file:

# -*- mode: ruby -*-
# vi: set ft=ruby :

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'

Vagrant.configure("2") do |config|
  ##### DEFINE VM #####
  config.vm.define "ubuntu-01" do |config|
  config.vm.hostname = "ubuntu-01"
  config.vm.box = "generic/ubuntu1804"
  config.vm.box_check_update = false
  config.vm.network "private_network", ip: "192.168.10.50"
  end
end

Note: Change the IP address to match your network scheme, but make sure it's on a different subnet.

vagrant up

This will spin up the image and launch the virtual machine (Figure B).

Figure B

Figure B

Our Ubuntu virtual machine ready for action.


You can now SSH into that VM with the command:

vagrant ssh

At this point, you can work on that generic Ubuntu platform. When you're finished, issue the exit command and issue one of the following:

  • Shut down the VM with the command vagrant halt.
  • Hibernate the VM with the command vagrant suspend.
  • Destroy the VM with the command vagrant destroy.

And that's all there is to using Vagrant to spin up virtual machines. Happy developing.

Also see

vagranthero.jpg
Image: HashiCorp

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox