Complete guide to installing and using Vagrant on Hyper-V in Windows 11

Last update: 08/04/2025

  • Vagrant supports Hyper-V from Windows 8.1 or higher and facilitates reproducible environments
  • Installing and configuring Vagrant on Hyper-V requires specific networking and provisioning settings.
  • Hyper-V does not allow certain features like static IPs easily, but there are complementary solutions
  • It is recommended to use Hyper-V compatible 'box' images to avoid boot errors.
Install Vagrant on Hyper-V-1

 

Input, Set up virtual environments quickly and orderly in Windows It seems like a complex mission. Fortunately, we have tools like Vagrant on Hyper-V to make this possible. And although its use is more associated with VirtualBox, it's also fully compatible with this virtualization technology, which is already integrated into many versions of Windows.

Despite that, installing and configuring Vagrant in Hyper-V is not as easy as it seems. There are key steps and peculiarities of Microsoft's virtualization provider that you should know. In this article, we'll provide you with everything you need to launch virtual environments following this formula without any problems.

What is Vagrant and why use Hyper-V?

Vagrant is a open source tool allowing build reproducible and portable virtual environments through simple configuration files. It is designed for developers, system administrators, or anyone who needs consistent environments across computers, with support for multiple operating systems.

For its part, Hyper-V is Microsoft's native hypervisor, included in Professional, Enterprise, and Education versions of Windows 8.1 and later. It offers high performance and stability, especially useful when other hypervisors like VirtualBox cause conflicts in modern Windows environments.

One of the most common reasons for opting for Hyper-V instead of VirtualBox is that some products, such as DockerDesktop or WSL2 (Windows Subsystem for Linux), require Hyper-V to be enabled. This creates incompatibilities with VirtualBox, making Hyper-V the only valid solution if you don't want to be activating and deactivating services.

Exclusive content - Click Here  How to add the symbols to the keyboard with Kika Keyboard?

Advantages of using Vagrant with Hyper-V

Installing Vagrant and Enabling Hyper-V

Before you start using Vagrant on Hyper-V, Make sure your computer has Hyper-V enabled. Be careful, as it's not usually enabled by default. You can do this manually from the "Turn on Windows features" section or with the following command in PowerShell (as administrator):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

After executing this command, a computer restart is required for the changes to take effect.

In parallel, you must Download and install Vagrant from the official websiteThe installer includes everything you need to use the command vagrant directly from any terminal.

Once installed, you can verify that everything is correct by running the following in the terminal:

vagrant --version

This command should return the installed version, for example Vagrant 2.4.0.

Step 1: Prepare a base environment

Vagrant is based on “boxes”, which are base images of pre-installed operating systemsThese are automatically downloaded from the public index known as Vagrant Cloud. To get started, you'll need to create a folder where you'll work on your project. For example:

mkdir mi_proyecto_vagrant
cd mi_proyecto_vagrant
vagrant init generic/alpine36

This command will generate a file called Vagrantfile This is where all the virtual machine settings reside. Within it, you'll need to adjust some key parameters to use Hyper-V.

Vagrant on Hyper-V

Hyper-V Provider Configuration

By default, Vagrant will try to use VirtualBox as a providerTo use Hyper-V, you can specify this each time by running:

vagrant up --provider=hyperv

Or, set Hyper-V as the default provider by setting an environment variable:

$env:VAGRANT_DEFAULT_PROVIDER="hyperv"

This step can be done from PowerShell or directly in your system environment variables.

Exclusive content - Click Here  Differences between TikTok and Douyin: Everything you need to know

Inside the Vagrantfile, It is recommended to specify the provider with specific settingsA basic example would be:

Vagrant.configure("2") do |config|
  config.vm.box = "generic/alpine36"
  config.vm.provider "hyperv" do |h|
    h.vmname = "mi_vm_hyperv"
    h.memory = 2048
    h.cpus = 2
  end
end

These parameters allow you to assign RAM, number of cores, and the name the machine will have in Hyper-V.

Networking and connectivity in Hyper-V

One of the weak points of Hyper-V in Vagrant is that it does not automatically configure the network. Therefore, you will need to manually select a vSwitch with external connectivity already created in Hyper-V.

To associate a private network or select a specific vSwitch, you can use:

config.vm.network "private_network", bridge: "NombreDelvSwitch"

Note that Hyper-V does not allow you to directly configure static IPs from Vagrant., so they must be set using scripts or by modifying the guest operating system settings.

 

hyper-v

Machine access: SSH and other tools

Although it may seem that SSH cannot be used on Windows, Vagrant includes a built-in SSH client, so you can access it without having to install additional programs.

Login with:

vagrant ssh

You can also use PuTTY, but in that case you will need Convert the private key generated by Vagrant into PPK format (with PuTTYgen), as it is not directly supported. The key is located at:

.vagrant/machines/default/hyperv/private_key

This will allow you to connect manually from any SSH client you prefer.

Provisioning with scripts

One of the biggest benefits of Vagrant is its support for automatic provisioning, thanks to scripts. You can launch shell scripts for repeatable installations:

config.vm.provision "shell", path: "bootstrap.sh"

Inside the file bootstrap.sh You can include instructions such as:

apk update
apk add git

This will run the first time the VM is createdIf you want to reapply the script later, you can do:

vagrant reload --provision

Provisioning VMs with scripts

Working with multiple machines

Vagrant allows you to manage multiple machines from a single file. This is useful for labs or server clusters. A typical lab setup might include multiple definitions:

Vagrant.configure("2") do |config|
  config.vm.define "master" do |master|
    master.vm.box = "bento/ubuntu-20.04"
    master.vm.hostname = "master"
    master.vm.network :private_network, ip: "10.0.0.10"
  end

  (1..2).each do |i|
    config.vm.define "node#{i}" do |node|
      node.vm.box = "bento/ubuntu-20.04"
      node.vm.hostname = "node#{i}"
      node.vm.network :private_network, ip: "10.0.0.#{i + 10}"
    end
  end

  config.vm.provision "shell", inline: <<-SHELL
    apt-get update
    apt-get install -y avahi-daemon libnss-mdns
  SHELL
end

This allows machines to recognize each other by names such as node1.local o master.local thanks to the use of mDNS.

Exclusive content - Click Here  How to copy and paste from a PDF

Performance and Compatibility Tips

Vagrant performance on Hyper-V is generally good, but it depends on:

  • The power of your host team (RAM, CPU, disk type).
  • The base image used (better to use optimized boxes).
  • The number of machines running at the same time.
  • Differential disk usage and thin provisioning.

A common practice for scripting multiple environments is to create a personalized box that already includes all your categories: tools, services, routes, etc. This avoids having to reinstall the same thing in each instance.

Using Vagrant on Hyper-V on Windows is totally viable, although with some limitations that can be solved with small adjustments. Hyper-V provides robustness and compatibility with modern Microsoft technologies, while Vagrant facilitates the automation and portability of the development environment.