Vagrant: running any vagrant command causes a powershell error - failed to locate powershell on PATH

Created on 31 Aug 2018  ยท  21Comments  ยท  Source: hashicorp/vagrant

Vagrant version

2.1.4

Host operating system

windows + cygwin

Guest operating system

centos

Vagrantfile

#-*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
echo test
SCRIPT
Vagrant.configure(2) do |config|
  config.vm.define "test" do |test|
    test.vm.box = "bento/centos-7.2"
    test.vm.network "private_network", ip: "172.28.128.13" #, nic_type: "virtio"
    test.vm.provider "virtualbox" do |vb, override|
      vb.memory = "8192"
      vb.cpus = 2
    end
    #test.vm.provision "shell", inline: $script
  end
end

Debug output

https://gist.github.com/spacerainbow000/54b0224837b1200ccd3288447884d1aa

Expected behavior

vagrant should be able to find powershell:

aembree @ vagrant [ 11:12 ] >>> vagrant ssh
Failed to locate the powershell executable on the available PATH. Please
ensure powershell is installed and available on the local PATH, then
run the command again.
aembree @ vagrant [ 11:12 ] >>> which powershell
/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell

Actual behavior

I get the powershell-related error above every time

Steps to reproduce

  1. install most recent vagrant version (I was also able to repro on 2.1.2) on windows w/cygwin
  2. try to run vagrant up
    I currently have powershell 5.1:
PS C:\cygwin64\home\aembree\vagrant> get-host
get-host


Name             : ConsoleHost
Version          : 5.1.16299.98
InstanceId       : 47bfd640-f4eb-4523-ba95-d893e8bc8edf
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

this worked on my previous vagrant version, which I'm pretty sure was 1.9.6 or something like that

References

none

hoswindows needs-repro

Most helpful comment

Fixed this by adding "%SYSTEMROOT%System32WindowsPowerShellv1.0" to the environment PATH

All 21 comments

also: running cygwin as administrator and opening a powershell prompt as admin (both suggestions in SO posts abt this issue) did not resolve the issue

Do you have a PATHEXT environment variable set in your cygwin environment?

yep

aembree @ vagrant [ 11:27 ] >>> echo $PATHEXT
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Can you try setting the environment variable to:

;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

and see if it works?

it doesn't:

aembree @ vagrant [ 11:43 ] >>> vagrant ssh
Failed to locate the powershell executable on the available PATH. Please
ensure powershell is installed and available on the local PATH, then
run the command again.
aembree @ vagrant [ 11:43 ] >>> echo $PATHEXT
;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Thanks for checking. I'll get a cygwin install setup and have a closer look at why it's not finding it on the path.

any update on this? my vagrant install is unusable right now, and basically every older version I install has some other core-functionality-breaking bug on windows as well

I tried reverting powershell.rb to https://github.com/hashicorp/vagrant/blob/52e98ffdfb4e3ab414803c70fcb838a428d92659/lib/vagrant/util/powershell.rb and it changed the text of the error, but the gist of the error is the same:

The executable 'powershell' 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 tried modifying which.rb adding:

19          #cygwin
20          cmd = 'which #{cmd}'
21          return `#{cmd}`

to the top of self.which, but this just gave me more errors that IMO don't really make sense:

C:/HashiCorp/Vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/util/which.rb:21:in ``': No such file or directory - which #{cmd} (Errno::ENOENT)

I don't know any ruby, but aren't backticks supposed to execute shell commands? not really sure how to progress this

what I tried looks like it actually works in irb:

irb(main):001:0> print `which powershell`
/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell
=> nil

any updates on this? my vagrant has been broken for like a month :S

can I at least get a recommendation for a version of vagrant + virtualbox that will be stable on windows + cygwin @chrisroberts

@spacerainbow000 - Have you tried any other windows shell applications like msys2 or git bash? WSL? Powershell directly? Maybe even re-installing cygwin? Also what version of Windows are you running?

Maybe also uninstall and re-install Vagrant since you were messing with ruby files?

i rolled back to 1.9.1 and virtualbox 5.1, which seems to be stable for the moment - since I have a working install now i'd rather not try anything that might break it again

Fixed this by adding "%SYSTEMROOT%System32WindowsPowerShellv1.0" to the environment PATH

I encountered this error when attempting to run a vagrant command on git bash in Windows 64. As soon as I started git bash with administrator's privileges, I was able to run commands with no problem.

export PATH=$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0

Thanks @nunoxavier, I met same problem, I tried your solve method. It works.

Hi there,

It looks like this has been resolved within a previously shipped version of Vagrant so I am now closing this issue. If the original issue was not fully resolved, please reopen this issue or create a new one.

Cheers!

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings