How to set up Vagrant with Virtual Box for a virtual Linux environment on your computer

Yes, it is possible to partition your hard drive and install a Linux operating environment on a separate partition from your already existing operating system (in this case, Windows). But what if you could run both on the same partition, without having to switch between both now and then? Well, this option may not be a replica of a full installation, but at least you get to access the command line, Linux-style, which is what most programmers prefer. With Vagrant and Oracle VM Virtual Box installed on your computer, you can do just that, imitate a Linux command line environment, complete with programs, packages and features installed (although you’ll have to install any that you need that are unavailable, however, that’s without a hassle).

Virtual Machines, as their name implies, are just virtual environments or computers that will emulate a physical machine (physical computer) while running on it. It will maintain a stable processing environment separate from the host computer. This way, you can install software and packages on the virtual machine and run them separately from the host computer as well. VirtualBox is a Virtual Machine provider. It creates a virtual environment in which an emulator resides (in this case, Vagrant). It’s a common choice for virtual machine providers, although not the only choice, it is free and not difficult to install.

In the next section, I’m going to walk you through the steps involved in setting up VirtualBox and Vagrant on your computer.

Step 1:

First off, you need to download the VirtualBox installation package from their official website here (Make sure to always download software packages from their official website, rather than from a third-party, for the sake of authenticity).

After downloading, click to install the package on your computer. This is a pretty straightforward process. Just carefully read and follow whatever prompts appear.

Step 2:

Now you need to download Vagrant as well from here for 64-bit users and here for 32-bit users. Also, click to install just like you did VirtualBox.

Step 3:

Now to create the virtual environment, we will need to execute it using Command Prompt (for Windows users). Open Command Prompt and add the Ubuntu 20.04 (Focal) image to your box list by typing the following into your command line and hitting enter:

vagrant box add ubuntu/focal64

You should see something like this on your command line:

Note: This process may take time but you don’t need to interrupt it to avoid issues with the installation.

Step 4:

In this step, you create your first virtual machine by entering the following and hitting enter:

vagrant init ubuntu/focal64

You should see the following on your command line:

This will create a Vagrant file ubuntu/focal64. You don’t have to do this every time you enter your command line to access your Vagrant machine, it is a one-time step just for installation only.

Step 5:

The host’s VirtualBox Guest Additions must be installed on your system. The following line of command does that:

vagrant plugin install vagrant-vbguest

Step 6:

At this point, VirtualBox and Vagrant should have completely been installed on your computer. The next step involves starting your virtual machine. Type in the following command to do just that:

vagrant up

This boots up Vagrant on your machine:

Step 7:

This step takes you into your virtual machine via the Secure Shell Protocol (SSHP). Type in the following line of command:

vagrant ssh

Note: Anytime you need to boot into your Virtual machine, just open up your terminal (it could be Command Prompt or PowerShell), and follow steps 6 and 7.

And you’re all done!

If you don’t have a Linux operating system as your primary operating system on your computer, I assure you, you’ll find this useful in your software development journey.

Keep coding💻✌😎!