HashiCorp Vagrant provides the same, easy workflow regardless of your role as a developer, operator, or designer. It leverages a declarative configuration file that describes all your software requirements, packages, operating system configuration, users, and more.
This tutorial will guide you to install Vagrant to Windows using WSL 2 (Windows Subsystem for Linux) with VirtualBox provider.
- Windows 10 - version +19042.928
- VirtualBox - version +6.1.22
- WSL 2
Just go to the download page and download the VirtualBox executable for Windows, then run it:
Install WSL 2
You must use WSL2. To install it, check the official documentation. I'll not set the guide here because it changes all the time:
Now open PowerShell and check if it's working properly and you are using version 2:
You must install Vagrant inside WSL. So you must download the Linux version.
Considering you're using Ubuntu 20.04, run:
# run inside WSL 2 # check https://www.vagrantup.com/downloads for more info curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" sudo apt-get update && sudo apt-get install vagrant
Them you must enable WSL 2 support. To do that, append two lines into the
# append those two lines into ~/.bashrc echo 'export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"' >> ~/.bashrc echo 'export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"' >> ~/.bashrc # now reload the ~/.bashrc file source ~/.bashrc
Hello world with Vagrant for WSL2
Now that you have everything installed and configured, let's create a simple hello world project.
You'll need to go to Windows files using the WSL, then run every Vagrant command from there:
# Go to Windows user's dir from WSL cd /mnt/c/Users/<my-user-name>/ # Create a project dir mkdir -p projects/vagrant-demo cd projects/vagrant-demo # Create a Vagrantfile using Vagrant CLI vagrant init hashicorp/bionic64 ls -l Vagrantfile # Start a VM using Vagrantfile vagrant up # Login to the VM # (password is 'vagrant') vagrant ssh # Done :)
- VirtualBox download page
- Vagrant Quick Start tutorial
- Vagrant and Windows Subsystem for Linux