How to Setup Vagrant with VirtualBox on Ubuntu 16.04 | 18.04

Vagrant is a tool for building and managing virtual machine environments via the command line. Out of the box, machines are provisioned on top of VirtualBox, VMware, AWS, but also works with other virtualization software providers…

Vagrant is great for developers as it isolates machine dependencies and their configurations within a single disposable, consistent environment, so whether you are working on Linux, Mac OS X, or Windows, everyone will be running the same code in the same environment, against the same dependencies and configured the same way..

This brief tutorial shows students and new users how to install Vagrant tool with VirtualBox support on Ubuntu 16.04 | 18.04..When you’re ready to setup Vagrant, follow the steps below:

Step 1: Install VirtualBox

Since we’re going to be using Vagrant with VirtualBox, our first step is to install VirtualBox… VirtualBox packages come with Ubuntu by default…

So to install it, run the commands below:

sudo apt update
sudo apt install virtualbox

Running the commands above to install VirtualBox won’t necessarily install the latest version of VirtualBox.. To install the latest, you will want to follow the post below:

VirtualBox 6.0.4 Released — Here’s How to Install / Upgrade on Ubuntu 16.04 | 18.04

That will get VirtualBox installed.

Step 2: Install Vagrant

Now that VirtualBox is installed, run the commands below to install Vagrant..

sudo apt install vagrant

Again, Vagrant packages come with Ubuntu default repositories… However, the packages might not be the latest… To get the latest, you may have to manually download and install Vagrant from its download page

After installing both VirtualBox and Vagrant, continue below to configure your Vagrant project folder…

Step 3: Setup Vagrant Environment

To setup Vagrant project environment, run the commands below to create a project folder in your home directory..

cd ~/
mkdir vagrant_project
cd ~/vagrant_project

After that, run the commands below to create your first virtualized machine for Ubuntu 18.04 64-bit.. If you want to create a vagrant machine file for CentOS 7, you’ll use centos/7 instead..

vagrant init ubuntu/bionic64

You’ll get similar message as below after running the commands above:

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.

After that, all you do is run the commands below to allow Vagrant to build a Ubuntu 18.04 machine with default configurations… If you want to edit the machine parameters, you can edit the file based on the help document below:

https://www.vagrantup.com/docs/vagrantfile/

Now, run the commands below to build Vagrant machine with default configurations…

vagrant up

You should see Vagrant build process started… It should download Ubuntu ISO image and setup the environment for it based on its default configuration settings for Ubuntu 18.04..

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/bionic64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/bionic64'
    default: URL: https://vagrantcloud.com/ubuntu/bionic64
==> default: Adding box 'ubuntu/bionic64' (v20190222.0.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/ubuntu/boxes/bionic64/versions/20190222.0.0/providers/virtualbox.box
==> default: Successfully added box 'ubuntu/bionic64' (v20190222.0.0) for 'virtualbox'!
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' is up to date...
==> default: Setting the name of the VM: vagrant_project_default_1551109348690_64011
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> 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...

Wait for the setup to complete and start using the your environment.

After building the VM, you simply use SSH to connect to it..

vagrant ssh

That’s it!

If you want to stop the VM, run the commands below

vagrant halt

Or Complete delete it by running the destroy command…

vagrant destroy

Congratulations! You have successfully installed Vagrant and VirtualBox to setup your Vagrant VM environment…

You may also like the post below:

Adding New Websites to Google AdSense Sites List

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.