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.
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.
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.
When the image download is complete, Vagrant will inform you of its success. Next create a new directory for the VM with the command:
Change into that newly created directory with the command:
Create a new Vagrant file with the command:
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.
This will spin up the image and launch the virtual machine (Figure B).
You can now SSH into that VM with the command:
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.
- How to create and use VirtualBox Groups (TechRepublic)
- Three ways to try Red Hat Ansible Tower - Free Trial (Red Hat)
- How to use Antsle to quickly deploy a virtual machine (TechRepublic)
- AWS RoboMaker: A cheat sheet (TechRepublic)
- Kali Linux for Vagrant: Hands-on (ZDNet)
- What is cloud computing? Everything you need to know about the cloud, explained (ZDNet)
- Best cloud services for small businesses (CNET)
- Microsoft Office vs Google Docs Suite vs LibreOffice (Download.com)
- Cloud computing: More must-read coverage (TechRepublic on Flipboard)
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.