Open ShahradR opened 4 years ago
Tried installing Vagrant on both WSL and Linux with the same version, but the problem still occurs.
Ran Process Explorer, and found that the following command is ran by Vagrant to determine the PowerShell version:
powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Write-Output $PSVersionTable.PSVersion.Major"
The process to find the above command is illustrated in the GIF below:
Running the PowerShell command in WSL manually, we see that it returns the expected major version number, 5
.
(Note that we have to escape the
$
symbol or Bash will try to resolve PSVersionTable
as a variable.)
Running Vagrant with the -debug
flag shows some additional insights. It seems that there are two lines returned from the PowerShell command's output: the expected major version number of 5
, but also a blank line. It is possible that Vagrant is only picking up the last empty line, and comparing it to the minimum supported PS version of 3
.
Changing the WSL version from 2 back to 1 resolves the issue – the vagrant init
command now completes successfully.
Notice that, in the debug output for the vagrant init
command, the blank line seen from the PowerShell command output in WSL 2 is absent once the distribution is converted back to WSL 1.
When running Vagrant in WSL, the following error message is returned: