Overview
I’ve never really been a huge fan of the Windows shell. They’ve come up with quite a few solutions, and there were also third party tools like Cygwin. Yet, Linux has been the default development environment for me (and most developers around the world. MAC is linux based too š )
Recently Microsoft did something HUGE. After officially providing WSL interoperability support one can now invoke binaries (exe files) from within the Ubuntu BASH on Windows. This makes working with development environments like Vagrant and VVV on your Windows 10 extremely easy and smooth. I had to do a lot of digging to get this working but at the end it’s pretty straightforward.
We are basically going to run Vagrant.exe inside BASH on Windows, and not the native Linux version of Vagrant which can be installed using apt-get install. (The issue with the Linux version of Vagrant is that VirtualBox fails to load, and telling BASH to load native Linux Vagrant with the Windows binary for VirtualBox is complicated (and didn’t work for me). So may be they’ll improve this in the future.)
This is what I mean:
In Part 1 we’ll focus on the installation.
(Note: WSL is still in its BETA release. If you’ve come this far you know who you are and what you’re doing. Use at your own risk.)
Step 1: Get the WSL – BASH on Windows from Microsoft
- Detailed instructions are here: https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
- After completing the setup see if you can run notepad.exe as indicated here: https://msdn.microsoft.com/en-us/commandline/wsl/interop. You need the Window 10 Anniversary Update build 14951 or higher for this to work. Link to the Creators Update for Windows 10. Some reading to understand what all is possible: https://blogs.msdn.microsoft.com/wsl/2016/10/19/windows-and-ubuntu-interoperability/
Step 2: Get Vagrant, VirtualBox and Git for Windows
- Get and install Git for Windows. We need this to get SSH to work with vagrant ssh
- Get and install Vagrant for Windows. At the time of writing this article I have Vagrant 1.9.5
- Get and install VirutalBox for Windows. At the time of writing this article I have VirtualBox 5.1.22r115126
UPDATE:
After the recent Windows 10 update to version 1709, I was not able to start my VM from Vagrant or VirtualBox (code E_FAIL (0x80004005)). I had to update both VirtualBox and Vagrant to the latest versions to overcome the problem. VirtualBox was updated to version 5.2.6r120293 and Vagrant was updated to version 2.0.1
Step 3: Include the location for exe in your Windows PATH environment variable
- See the screenshot below. You should include the path where you have installed the programs. In my case I installed everything under E:\ProgramFiles.
- You may need to restart your system for these settings to take effect.
Note: For SSH you have to include the Git\usr\bin path which holds the ssh binary.
Step 4: Test using Bash on Windows
- Open BASH on Ubuntu on Windows from your Start Menu.
Note: I am currently running the BASH as an Administrator (right click Run as Administrator). VirtualBox requires administrator privileges for some reason, and there were issues with accessing the windows directory using a regular user account as well. - Test if the following commands work.
>VBoxManage.exe --version >vagrant --version >ssh.exe
UPDATE:
Tested and works with Vagrant 2.0.1 and VirtualBox 5.2
Step 5: Create Symbolic links to the EXEs (Optional)
I like using the Linux syntax only (without .exe). To get that to work create symbolic links from the BASH as below:
sudo ln -s UNIX_PATH_TO_YOUR_EXE /usr/local/bin/EXE_NAME
>sudo ln -s /mnt/e/ProgramFiles/VirtualBox\ 5.0.20/VBoxManage.exe /usr/local/bin/VBoxManage >sudo ln -s /mnt/e/ProgramFiles/HashiCorp/Vagrant/bin/vagrant.exe /usr/local/bin/vagrant
You’re Set:
That’s it. You now have Vagrant in BASH. Run vagrant up
with your config file and you’re good to go.
In Part 2 we’ll look at running VVV – the WordPress development environment
Kevin says
I followed your instructions and everything worked great, except the symlink for vagrant.exe doesn’t work. I’m running Win10 Enterprise v1703 (creators update). Vagrant 2.01. I used the windows installer and had it install in the default location (C:\HashiCorp\Vagrant\bin\vagrant.exe.
Karan NA Gupta says
Hi Kevin
I’ve created the symbolic link in the “/usr/local/bin/” directory from the BASH shell. “/usr/local/bin” is normally available in the default path, and so running the link from any directory should work. Could you check where you created the target link, and verify that the target directory is available in the path using: echo $PATH.
You could also test if the “ln -s” command worked successfully by checking if the output of the command: “echo $?” is 0. Hope this helps.