3

I want to run vagrant up in Debian WSL from a Windows terminal. I have installed vagrant:

/mnt/c/HS_DEV/Homestead$ vagrant --version

I get

Vagrant 2.2.6

When I run vagrant up, I get:

The executable 'cmd.exe' Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.

So I'm trying to use debian.exe instead of the default cmd.exe in the config of Windows terminal, but it is still not working. How can I run vagrant up? Where did this issue come from?

I noticed that it works if I use powershell, cmd.exe, and gitbash, but I want to do it in my Debian WSL.

2
  • See Vagrant webpage, check the installed version , enable Windows access and modify the PATH. – GAD3R Dec 30 '20 at 8:27
  • @GAD3R i enabled windows access, but i don't know what to add in the path, i try to add my path to debian.exe, but i still have the same issue – Axel AMGHAR Dec 30 '20 at 8:45
1

Full disclosure - I do not use Vagrant, but having run into similar PATH issues on WSL in the past, I'm still hopeful that this will be the solution to your issue.

First, I'm assuming that you are using the WSL instructions for Vagrant. If so, then you have two versions of Vagrant installed. The first is the Windows version (since you mention running it under PowerShell and cmd), and as the docs say, "While the vagrant.exe executable provided by the Vagrant Windows installation is accessible from within the WSL, it will not function as expected."

So if you've followed those instructions, you've also installed the Debian version into your WSL instance via the .deb file.

But is WSL actually using the Debian version? Most likely not. Since you have the Windows version also installed, and WSL "helpfully" prepends your Windows path to your WSL path, running vagrant up from inside WSL/Debian is likely still finding the first vagrant on your path, which is likely the Windows version. This is actually a very common problem with WSL and having both Windows and Linux versions of a tool installed.

You can check this by running which vagrant from inside Debian and seeing which executable is found. If it's the Windows version, then hopefully this is the culprit.

There are a few possible workarounds for this that I know of:

  1. Create a startup script (e.g. bashrc or equivalent for your shell of choice) which removes the Windows node from path, or at least gives the Linux version higher precedence.

  2. Create a /etc/wsl.conf with ...

    [interop]
    appendWindowsPath = false
    

    This will remove all Windows paths from the WSL session. The downside is that some useful Windows utilities will no longer be in the WSL path, but you can always add them back in manually in your startup scripts. This is probably easier from a scripting perspective than removing paths manually, at least.

  3. If you don't need it anymore, and will be using the Linux/WSL version exclusively, you could uninstall the Windows Vagrant.

8
  • First thanks for the anwser and the clear explanation, i was able to understand better installation of vagrant in windows vs installation on debian. I have a version of vagrant installed in windows, and then like you said i installed the version on debian with the last .deb. So when i use which vagrant , i get /usr/bin/vagrant . i tried your 2 and 3 solutions. I create the wsl.conf but nothings change, and i uninstalled the windows version of vagrant but i keep getting the same error. I am currently trying to reinstall the windows version – Axel AMGHAR Dec 31 '20 at 10:47
  • I also try export PATH="$PATH:/opt/vagrant/bin" to use the vagrant debian version, then i try export PATH="$PATH:/opt/vagrant/bin/vagrant". But i also try with the windows version like that => export PATH="$PATH:/mnt/c/Hashicorp/Vagrant/bin/vagrant" and export PATH="$PATH:/mnt/c/Hashicorp/Vagrant/bin" – Axel AMGHAR Dec 31 '20 at 13:07
  • With all of those PATH modifications, you are appending to the path, so if there's another version already in the path, the existing version will have precedence, and those statements aren't going to do anything. Try export PATH=/opt/vagrant/bin:$PATH instead to prepend and have /opt/vagrant/bin take precedence. – NotTheDr01ds Dec 31 '20 at 15:26
  • 1
    I didn't know ot will take append to the path, thanks. So i tried export PATH=/opt/vagrant/bin:$PATH and export PATH=/opt/vagrant/bin/vagrant:$PATH Also i reinstalled the debian version of vagrant and now when i do which vagrant i get /opt/vagrant/bin/vagrant. And i have still the same cmd.exe error – Axel AMGHAR Dec 31 '20 at 16:03
  • 1
    It should be enabled. If not i will have this error Vagrant will not operate outside the Windows Subsystem for Linux unless explicitly instructed. Due to the inability to enforce expected Linux file ownership and permissions on the Windows system, Vagrant will not make modifications to prevent unexpected errors. To learn more about this, and the options that are available, please refer to the Vagrant documentation: https://www.vagrantup.com/docs/other/wsl.html i get 1 in response also – Axel AMGHAR Dec 31 '20 at 16:21
1

Please make sure you are using the latest version of Vagrant, or at least 2.2.15, otherwise it may not be able to run Windows executable files correctly from Linux.

Just add path to cmd.exe in Linux:

export PATH="$PATH:/mnt/c/Windows/System32"

Otherwise, you will get the following error, as you have described:

The executable 'cmd.exe' Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.

You can add the above line to your ~/.profile file and reload it using the following commands:

nano ~/.profile
source ~/.profile

This way, Vagrant will be able to locate the cmd.exe.

Through the environment variable VAGRANT_WSL_ENABLE_WINDOWS_ACCESS, Vagrant understands that it may access the Windows system to run executable files and use functions such as synced folders. You can find more information about this variable on the corresponding page of the official Vagrant website.

export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"

With this variable, Vagrant will start Windows executables files from Linux, including the Windows cmd.exe command-line interpreter.

There is a YouTube video on how to install Vagrant under Ubuntu 18 in WSL1 of Windows 10 and VirtualBox. However, since this video demonstrates the use of old software, newer software may not work as described in the video. Besides that, the video does not explicitly address the issue with the cmd.exe that you have described.

In any case, running Vagrant from Linux to create a virtual machine in Windows VirtualBox does not always run smoothly. You may encounter errors similar to the following:

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "a1d5c124-261b-4e4b-a11a-88f7bfdda6df", "--type", "headless"]

Stderr: VBoxManage.exe: error: Failed to get device handle and/or partition ID for 
0000000001cf34e0 (hPartitionDevice=0000000000000a39, Last=0xc0000002/1) 
(VERR_NEM_VM_CREATE_FAILED)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole

To avoid these errors and make Vagrant work reliably, you need to run Linux on physical hardware instead of running from a Windows WSL or Docker container. If you run Linux on physical hardware, VirtualBox will also run on Linux, and Vagrant would not need to communicate between Linux and Windows by running Windows executables on Linux.

3
  • 1
    Thanks for the response, it's help a lot, i tried different approches, but i finnaly run vagrant directly in my cmd.exe, i can also use gitbash to run vagrant from windows with linux commands. I will try to use your method in the future if i need it for a new project – Axel AMGHAR Feb 16 at 15:17
  • 1
    @AxelAMGHAR - did you try to run Linux on physical hardware instead of running from a Windows WSL or Docker container? Did it make any difference? For example, you can rent a server at Hetzner hetzner.com/sb for about €30/month. These servers are old, but working, and with 32 GB RAM you will have space for virtual machines. You can search for "v3", "v4", "v5", etc to filter by CPU generation. For example, v3 are Xeon processors released in or around year 2014, v5 are released in or around 2015, v6 released in 2017, and so on. On physical hardware without WSL it should run smoothly! – Maxim Masiutin Feb 17 at 8:11
  • I didn't try on linux software, the only thing that i wanted was to run it in windows terminal since windows terminal allow you to use multiple tabs. And i tried to use the gitbash terminal in windows terminal, but don't find any way to use it there. So i used the wsl instead. And unlike gitbash terminal who use the windows applications, wsl was using is own application so vagrant was not availbale. It's hard to explain it easily, but i hope you get my point. – Axel AMGHAR Feb 22 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.