Install Vagrant with VirtualBox on Ubuntu 18

Share on Social Media

Learn how to install Vagrant with VirtualBox on Ubuntu Server 18. Follow our step-by-step guide to set up your development environment easily and efficiently. #centlinux #ubuntu #vagrant #virtualbox

What is Vagrant?

Vagrant is an open source software for building and managing portable virtual software development environments e.g. VirtualBox, KVM, Docker, VMWare, AWS, etc. Vagrant is used to simplify software configuration management and virtualization. Vagrant is developed by HashiCorp and distributed under MIT license.

Vagrant support most popular software development environments e.g. VirtualBox, Docker, KVM, etc. These development environments are called Providers while the Vagrant is termed as Provisioner. A Provisioner (Vagrant) is combined with a Provider (such as VirtualBox) to setup a Vagrant host environment.

In this article, you will learn how to install Vagrant with VirtualBox on Ubuntu Linux Server. If you intend to use CentOS instead of Ubuntu then you should refer to our previous post on how to configure Vagrant with VirtualBox on CentOS 7.

Install Vagrant with VirtualBox on Ubuntu Server 18
Install Vagrant with VirtualBox on Ubuntu Server 18

Ubuntu Server Specification

We are using a minimal Ubuntu Server machine with following specification.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 40 GB
  • Operating System – Ubuntu Server 18.04 LTS
  • Hostname – vagrant-01.centlinux.com
  • IP Address – 192.168.116.219 /24

Recommended Training: Vagrant Up! Comprehensive development system automation from Jason Taylor, John Myers

298108 3f58 3
show?id=oLRJ54lcVEg&bids=1597309

Install VirtualBox on Ubuntu Server

Connect with vagrant-01.centlinux.com as an admin user by using an ssh tool.

Vagrant requires a provider such as VirtualBox, Docker, KVM (libvirt), etc. to support provisioning of required virtual machines or containers.

Here, we are installing VirtualBox as the provider for Vagrant.

We have VirtualBox 5.2 available in standard APT repository, therefore, we are installing it easily by using an apt command.

sudo apt install -y virtualbox

If you wish to install a latest version of VirtualBox then you should follow our previous article: Install Oracle VirtualBox on Ubuntu Server.

Install Vagrant on Ubuntu Server

Vagrant 2.0.2 is available in standard APT repository. But for the sake of demonstration, we are installing the latest version Vagrant 2.2.7, that was available on Vagrant official website.

Download Vagrant according to your distro and architecture. Since, we are installing on a 64-bit Ubuntu Server 18.04 LTS, therefore, we are downloading the Debian 64-bit package file.

cd /tmp
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb

Install Vagrant from the downloaded package by using the apt command.

sudo apt install ./vagrant_2.2.7_x86_64.deb

Output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'vagrant' instead of './vagrant_2.2.7_x86_64.deb'
The following NEW packages will be installed:
vagrant
0 upgraded, 1 newly installed, 0 to remove and 126 not upgraded.
Need to get 0 B/42.0 MB of archives.
After this operation, 121 MB of additional disk space will be used.
Get:1 /tmp/vagrant_2.2.7_x86_64.deb vagrant amd64 1:2.2.7 [42.0 MB]
Selecting previously unselected package vagrant.
(Reading database ... 87995 files and directories currently installed.)
Preparing to unpack /tmp/vagrant_2.2.7_x86_64.deb ...
Unpacking vagrant (1:2.2.7) ...
Setting up vagrant (1:2.2.7) ...

Verify installation of Vagrant by executing vagrant command and check its version.

cd
vagrant -v

Output:

Vagrant 2.2.7

Getting Started with Vagrant

We have successfully installed Vagrant 2.2.7. Now its time to use it to create a Vagrant box.

There is a huge collection of Vagrant boxes, available at HashiCorp Vagrant Cloud. You can search and use your required boxes from here.

Vagrant Cloud - Boxes
Vagrant Cloud – Boxes

Here, we are creating a Debian virtual machine as follows.

Create a directory for our Vagrant machine.

mkdir debian
cd debian

Create a vagrantfile for our Debian virtual machine.

vagrant init debian/jessie64

Output:

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

This command creates a vagrantfile that will be used to provision our Debian virtual machine by using the Virtualbox provider.

Create and start our Debian virtual machine.

vagrant up

Output:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'debian/jessie64' version '8.11.1' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Installing rsync to the VM...
==> default: Rsyncing folder: /home/ahmer/debian/ => /vagrant

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default:
==> default: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports

Our required Debian machine has been created and started.

Connect to our Debian virtual machine by using ssh.

vagrant ssh

Output:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
vagrant@jessie:~$

Check Linux Kernel.

uname -a

Output:

Linux jessie 3.16.0-9-amd64 #1 SMP Debian 3.16.68-1 (2019-05-22) x86_64 GNU/Linux

The Debian machine is ready for use now, you can configure it according to your needs.

To shutdown this virtual machine, we can use the vagrant command.

vagrant halt

Output:

==> default: Attempting graceful shutdown of VM...

If a virtual machine is not required anymore, we can delete this Vagrant box using following command.

vagrant destroy

Output:

    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Destroying VM and associated drives...

Final Thoughts

Setting up Vagrant with VirtualBox on Ubuntu Server 18 can greatly streamline your development workflow, allowing you to manage and deploy virtual environments with ease. If you encounter any issues or need professional assistance, I’m here to help.

Searching for a skilled Linux admin? From server management to security, I ensure seamless operations for your Linux systems. Find out more on my Fiverr profile!

Looking for something?

Leave a Reply