Vagrant is a command-line tool for easily building and managing virtual machines. It is commonly used by developers to create test and production environments within a very short time. Vagrant requires a hypervisor to provision VMs on top of it and Virtualbox is the default provider for vagrant. It can use other hypervisors and providers such as VMware, Hyper-V, Docker, KVM and AWS.

In this guide, we are going to look at how to provision and run vagrant virtual machines on Hyper-V. I am using Windows 10 and we need to first enable Hyper-V Virtualization.

How to Enable Hyper-V on Windows 10

Open Control panel, click on Programs and select ‘Turn Windows Features on and off’. When presented with a list of programs, look for Hyper-V, expand it and select the two features under it.

Click Ok and restart your computer for the changes to take effect.

Install Vagrant on Windows 10

Once you have enabled Hyper-V, proceed to install Vagrant on your Windows machine. Download Vagrant from their official site. When downloaded, navigate to the folder and double-click on the installation file to install.

Click Next and accept the terms and conditions. Then click Next

Choose where to have vagrant installed.

Click Next then click install to begin the installation process.

Once installation progress is done, click finish

You will be prompted to restart your computer for the changes to take effect.

Running your First Vagrant VM on Hyper-V

A Vagrant Box is a package format for Vagrant Environment. Vagrant boxes are available publicly for download, but you can also create your custom boxes. To start with, let us grab an Ubuntu Vagrant Box from Hashicorp. Open PowerShell as Administrator and run the command as shown below:

$ vagrant box add hashicorp/bionic64

Once you hit Enter, you will be prompted to select the hypervisor to use as below. In this case, we are selecting hyper-v

Input the number 1 and press Enter to get Standard Ubuntu 18.04 LTS 64-bit box

Confirm that you have the box by running the below command:

$ vagrant box list

Expected Output

Vagrant boxes make use of vagrant files to spin virtual machines. Create a folder to store your Vagrant file, navigate to the folder and run the command below:

$ vagrant init hashicorp/bionic64

The above command creates and stores the Vagrantfile for our Ubuntu 18 Vagrant box. You should see this output:

Now bring up the virtual machine by running ‘vagrant up’ command in the Vagrantfile folder:

$ vagrant up --provider hyperv

Confirm from your Hyper-V environment that the VM has been created:

You can use the VM from hyper-v or you can ssh into it as shown:

$ vagrant ssh

Creating your Own Vagrantfiles

As stated earlier, Vagrant boxes are publicly available, where you can directly download, initialize to create their corresponding Vagrantfiles as run ‘vagrant up’ to bring up the virtual machines. However, you can also create your own customized vagrant boxes and share with the public. Stay tuned for my next tutorial on how to create your own vagrant boxes from scratch.

This guide is helpful in getting started with vagrant and hyperv on Windows and I hope you have enjoyed. For Vagrant with Linux and VirtualBox, check the below links:


Please enter your comment!
Please enter your name here