DEV Community

Sabrina Pereira
Sabrina Pereira

Posted on • Updated on

Vagrant and VirtualBox on Windows 11 and WSL

Download VirtualBox's latest version for Windows and its extension pack from here.

After installing VirtualBox, install the pack by going into tools > extensions then clicking install:

Image description

Install vagrant according to their instructions for Linux. All you have to do is to runt he following command in WSL:

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vagrant
Enter fullscreen mode Exit fullscreen mode

Export some global variables to be able to run vagrant (these need to be reset each time you open a new terminal):

export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
Enter fullscreen mode Exit fullscreen mode

You also have to add the folder where your project is located:

export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/<path-to-folder-where-Vagrantfile-is>"
Enter fullscreen mode Exit fullscreen mode

And you have to ssh from PowerShell 🫠

ssh vagrant@127.0.0.1 -p 2222
Enter fullscreen mode Exit fullscreen mode

Add this line to your Vagrantfile to be able to have a project in your ubuntu file system:

config.vm.synced_folder '.', '/vagrant', disabled: true
Enter fullscreen mode Exit fullscreen mode

For more info on WSL installs, click here.

Latest comments (0)