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
Table of Contents
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.
If you want learn about architecture and usage of Vagrant software, we highly recommend that you should read Vagrant: Up and Running (PAID LINK) by O’Reilly Media to have a thorough understanding of Vagrant concepts and command usage.
Recommended Online Training: Vagrant Up! Comprehensive development system automation
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
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.
ahmer@ubuntu-server:~$ sudo apt install -y virtualbox ... Setting up glib-networking:amd64 (2.56.0-1) ... Setting up libxt6:amd64 (1:1.1.5-1) ... Setting up libavahi-client3:amd64 (0.7-3.1ubuntu1.2) ... Setting up libegl-mesa0:amd64 (19.2.8-0ubuntu0~18.04.3) ... Setting up binutils (2.30-21ubuntu1~18.04.2) ... Setting up fontconfig (2.12.6-0ubuntu2) ... Regenerating fonts cache... done. Setting up libglx-mesa0:amd64 (19.2.8-0ubuntu0~18.04.3) ... Setting up libcups2:amd64 (2.2.7-1ubuntu2.7) ... Setting up libcairo2:amd64 (1.15.10-2ubuntu0.1) ... Setting up gcc-7 (7.5.0-3ubuntu1~18.04) ... Setting up g++-7 (7.5.0-3ubuntu1~18.04) ... Setting up libcairo-gobject2:amd64 (1.15.10-2ubuntu0.1) ... Setting up libsoup2.4-1:amd64 (2.62.1-1ubuntu0.4) ... Setting up libsoup-gnome2.4-1:amd64 (2.62.1-1ubuntu0.4) ... Setting up gcc (4:7.4.0-1ubuntu2.3) ... Setting up libpulse0:amd64 (1:11.1-1ubuntu7.4) ... Setting up libxmu6:amd64 (2:1.1.2-2) ... Setting up libegl1:amd64 (1.0.0-2ubuntu2.3) ... Setting up dpkg-dev (1.19.0.5ubuntu2.3) ... Setting up dkms (2.3-3ubuntu9.7) ... Setting up libpango-1.0-0:amd64 (1.40.14-1ubuntu0.1) ... Setting up g++ (4:7.4.0-1ubuntu2.3) ... update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode Setting up librest-0.7-0:amd64 (0.8.0-2) ... Setting up libglx0:amd64 (1.0.0-2ubuntu2.3) ... Setting up build-essential (12.4ubuntu1) ... Setting up virtualbox-dkms (5.2.34-dfsg-0~ubuntu18.04.1) ... Loading new virtualbox-5.2.34 DKMS files... Building for 4.15.0-76-generic Building initial module for 4.15.0-76-generic Done. vboxdrv: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.15.0-76-generic/updates/dkms/ vboxnetadp.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.15.0-76-generic/updates/dkms/ vboxnetflt.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.15.0-76-generic/updates/dkms/ vboxpci.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.15.0-76-generic/updates/dkms/ depmod........................ DKMS: install completed. Setting up libsdl1.2debian:amd64 (1.2.15+dfsg2-0.1ubuntu0.1) ... Setting up virtualbox (5.2.34-dfsg-0~ubuntu18.04.1) ... vboxweb.service is a disabled or a static unit, not starting it. Setting up libpangoft2-1.0-0:amd64 (1.40.14-1ubuntu0.1) ... Setting up libgl1:amd64 (1.0.0-2ubuntu2.3) ... Setting up libpangocairo-1.0-0:amd64 (1.40.14-1ubuntu0.1) ... Setting up libqt5gui5:amd64 (5.9.5+dfsg-0ubuntu2.5) ... Setting up libqt5x11extras5:amd64 (5.9.5-0ubuntu1) ... Setting up libqt5widgets5:amd64 (5.9.5+dfsg-0ubuntu2.5) ... Setting up librsvg2-2:amd64 (2.40.20-2) ... Setting up libqt5printsupport5:amd64 (5.9.5+dfsg-0ubuntu2.5) ... Setting up librsvg2-common:amd64 (2.40.20-2) ... Setting up libqt5opengl5:amd64 (5.9.5+dfsg-0ubuntu2.5) ... Setting up libqt5svg5:amd64 (5.9.5-0ubuntu1) ... Setting up virtualbox-qt (5.2.34-dfsg-0~ubuntu18.04.1) ... Setting up adwaita-icon-theme (3.28.0-1ubuntu1) ... update-alternatives: using /usr/share/icons/Adwaita/cursor.theme to provide /usr/share/icons/default/index.theme (x-cursor-theme) in auto mode Setting up humanity-icon-theme (0.6.15) ... Setting up libgtk-3-0:amd64 (3.22.30-1ubuntu4) ... Setting up libgtk-3-bin (3.22.30-1ubuntu4) ... Setting up qt5-gtk-platformtheme:amd64 (5.9.5+dfsg-0ubuntu2.5) ... Setting up ubuntu-mono (16.10+18.04.20181005-0ubuntu1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... Processing triggers for ureadahead (0.100.0-21) ... Processing triggers for systemd (237-3ubuntu10.24) ... Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.36.11-2) ...
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.
ahmer@ubuntu-server:~$ cd /tmp ahmer@ubuntu-server:/tmp$ wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb --2020-03-28 09:31:06-- https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.9.183, 2a04:4e42:2::439 Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.9.183|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 42001582 (40M) [application/x-debian-package] Saving to: âvagrant_2.2.7_x86_64.debâ vagrant_2.2.7_x86_6 100%[===================>] 40.06M 1.18MB/s in 34s 2020-03-28 09:31:41 (1.17 MB/s) - âvagrant_2.2.7_x86_64.debâ saved [42001582/42001582]
Install Vagrant from the downloaded package by using the apt command.
ahmer@ubuntu-server:/tmp$ sudo apt install ./vagrant_2.2.7_x86_64.deb 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.
ahmer@ubuntu-server:/tmp$ cd ahmer@ubuntu-server:~$ vagrant -v 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.
Here, we are creating a Debian virtual machine as follows.
Create a directory for our Vagrant machine.
ahmer@ubuntu-server:~$ mkdir debian ahmer@ubuntu-server:~$ cd debian
Create a vagrantfile for our Debian virtual machine.
ahmer@ubuntu-server:~/debian$ vagrant init debian/jessie64 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.
ahmer@ubuntu-server:~/debian$ vagrant up 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.
ahmer@ubuntu-server:~/debian$ vagrant ssh 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:~$ uname -a 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.
ahmer@ubuntu-server:~/debian$ vagrant halt ==> default: Attempting graceful shutdown of VM...
If a virtual machine is not required anymore, we can delete this Vagrant box using following command.
ahmer@ubuntu-server:~/debian$ vagrant destroy 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.
I offer expert services to install Vagrant with VirtualBox on your Linux System. Feel free to reach out to me on Fiverr for personalized support and a seamless setup experience.