New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL prefers NodeJS executable in Program Files over /usr/bin #1896

Open
Entroper opened this Issue Apr 12, 2017 · 16 comments

Comments

Projects
None yet
@Entroper

Entroper commented Apr 12, 2017

I've just tried installing NodeJS on WSL, after running the Creators Update and doing a fresh WSL install to get 16.04.

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Running node works fine:

$ node -v
v6.10.2

But npm doesn't work:

$ npm -v
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

It seems to be trying to run the npm executable from Windows. I tried some other things:

$ whereis npm
npm: /usr/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd /mnt/c/Users/Entroper/AppData/Roaming/npm/npm /mnt/c/Users/Entroper/AppData/Roaming/npm/npm.cmd
$ which npm
/usr/bin/npm
$ /usr/bin/npm -v
3.10.10
$ whereis node
node: /usr/bin/node /usr/include/node /mnt/c/Program Files/nodejs/node.exe /usr/share/man/man1/node.1.gz
$ which node
/usr/bin/node

So it obviously knows where the Linux npm is, and it seems to think that's the preferred one, but it doesn't run that one for some reason. And it clearly works if I specify the absolute path to npm.

@benhillis

This comment has been minimized.

Show comment
Hide comment
@benhillis

benhillis Apr 12, 2017

Member

I've set this up locally by installing the Windows and Linux versions of nodejs and I'm not hitting the same issue as you. My shell is correctly picking up the npm in /usr/bin and not the one in Program Files.

Could you share the output of the below commands?
echo $PATH
strace -v npm -v

It looks like you're running into similar issues as #1890. I'd suggest overwriting your $PATH environment variable in your .bashrc file or setting the registry key that disables appending the NT path.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss]
"AppendNtPath"=dword:00000000

Member

benhillis commented Apr 12, 2017

I've set this up locally by installing the Windows and Linux versions of nodejs and I'm not hitting the same issue as you. My shell is correctly picking up the npm in /usr/bin and not the one in Program Files.

Could you share the output of the below commands?
echo $PATH
strace -v npm -v

It looks like you're running into similar issues as #1890. I'd suggest overwriting your $PATH environment variable in your .bashrc file or setting the registry key that disables appending the NT path.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss]
"AppendNtPath"=dword:00000000

@benhillis benhillis added the interop label Apr 12, 2017

@Entroper

This comment has been minimized.

Show comment
Hide comment
@Entroper

Entroper Apr 12, 2017

Amusingly, the strace command worked perfectly -- it ran the Linux npm. I can attach the debug output, but it probably isn't useful. I'll give the $PATH thing a try.

EDIT: Oh, this is interesting. Before I did anything with $PATH or that registry key, I re-ran npm -v to make sure it still didn't work, which it didn't. Then I closed Ubuntu, and re-opened it... and now it works.

Entroper commented Apr 12, 2017

Amusingly, the strace command worked perfectly -- it ran the Linux npm. I can attach the debug output, but it probably isn't useful. I'll give the $PATH thing a try.

EDIT: Oh, this is interesting. Before I did anything with $PATH or that registry key, I re-ran npm -v to make sure it still didn't work, which it didn't. Then I closed Ubuntu, and re-opened it... and now it works.

@Entroper

This comment has been minimized.

Show comment
Hide comment
@Entroper

Entroper Apr 13, 2017

Since I can no longer reproduce the problem, and pathing issues are being looked into, I'll close this.

Entroper commented Apr 13, 2017

Since I can no longer reproduce the problem, and pathing issues are being looked into, I'll close this.

@Entroper Entroper closed this Apr 13, 2017

@ncla

This comment has been minimized.

Show comment
Hide comment
@ncla

ncla Apr 13, 2017

Had the same issue, and closing and opening bash solved that problem. Weird. I did uninstall Node from Windows before-hand.

ncla commented Apr 13, 2017

Had the same issue, and closing and opening bash solved that problem. Weird. I did uninstall Node from Windows before-hand.

@samplefrequency

This comment has been minimized.

Show comment
Hide comment
@samplefrequency

samplefrequency Apr 15, 2017

I'm running into the exact same issue.

I made sure Node was not installed under Windws and installed Node LTS under WSL. Everything worked perfectly. I was able to run my servers and builds while editing under the Windows environment. Problem is that my IDE has integrations that I would like to be able to use which requires Node for Windows.

I installed Node LTS For Windows and it gets added to the Windows path. Everything works fine under Windows but once I re-open a Bash on Windows instance, NPM utterly fails. Uninstalling Node for Windows and everything under WSL works again.

May someone post the $PATH workaround?

I may try the registry key just to keep the environment paths completely separate as at the moment I don't have a need to launch Windows executables via WSL.

samplefrequency commented Apr 15, 2017

I'm running into the exact same issue.

I made sure Node was not installed under Windws and installed Node LTS under WSL. Everything worked perfectly. I was able to run my servers and builds while editing under the Windows environment. Problem is that my IDE has integrations that I would like to be able to use which requires Node for Windows.

I installed Node LTS For Windows and it gets added to the Windows path. Everything works fine under Windows but once I re-open a Bash on Windows instance, NPM utterly fails. Uninstalling Node for Windows and everything under WSL works again.

May someone post the $PATH workaround?

I may try the registry key just to keep the environment paths completely separate as at the moment I don't have a need to launch Windows executables via WSL.

@Entroper

This comment has been minimized.

Show comment
Hide comment
@Entroper

Entroper Apr 15, 2017

I'll reopen this since others are still seeing this issue.

Entroper commented Apr 15, 2017

I'll reopen this since others are still seeing this issue.

@Entroper Entroper reopened this Apr 15, 2017

@Entroper Entroper changed the title from WSL prefers executable in Program Files over /usr/bin to WSL prefers executable in Program Files over /usr/bin (NodeJS) Apr 15, 2017

@Entroper Entroper changed the title from WSL prefers executable in Program Files over /usr/bin (NodeJS) to WSL prefers NodeJS executable in Program Files over /usr/bin Apr 15, 2017

@samplefrequency

This comment has been minimized.

Show comment
Hide comment
@samplefrequency

samplefrequency Apr 16, 2017

Re-installed Node for Windows (6.10.2) and this time, I set the installer to not add node and npm to the Windows path. I set my IDE to access the path to Node it requires (c:\program files\nodejs\node.exe) and invoke npm.cmd directly as well if I need to install npm modules in the Windows environment. Not ideal but seems to work for the moment.

Doing the above results in WSL using the proper Linux node and npm installations and Windows will properly use the Windows Node installation as well.

samplefrequency commented Apr 16, 2017

Re-installed Node for Windows (6.10.2) and this time, I set the installer to not add node and npm to the Windows path. I set my IDE to access the path to Node it requires (c:\program files\nodejs\node.exe) and invoke npm.cmd directly as well if I need to install npm modules in the Windows environment. Not ideal but seems to work for the moment.

Doing the above results in WSL using the proper Linux node and npm installations and Windows will properly use the Windows Node installation as well.

@dfbaskin

This comment has been minimized.

Show comment
Hide comment
@dfbaskin

dfbaskin Apr 20, 2017

Same thing, closing Bash and reopening fixed the issue.

dfbaskin commented Apr 20, 2017

Same thing, closing Bash and reopening fixed the issue.

@smalike

This comment has been minimized.

Show comment
Hide comment
@smalike

smalike Apr 20, 2017

Windows change npm to npm.exe fixed the issue.

smalike commented Apr 20, 2017

Windows change npm to npm.exe fixed the issue.

@samplefrequency

This comment has been minimized.

Show comment
Hide comment
@samplefrequency

samplefrequency Apr 20, 2017

@smalike Do you mean you changed npm.cmd to npm.exe?

samplefrequency commented Apr 20, 2017

@smalike Do you mean you changed npm.cmd to npm.exe?

@jmalczak

This comment has been minimized.

Show comment
Hide comment
@jmalczak

jmalczak Jun 12, 2017

@samplefrequency rename npm to npm_cygwin, since npm in program files is a bash script targeted for cygwin

jmalczak commented Jun 12, 2017

@samplefrequency rename npm to npm_cygwin, since npm in program files is a bash script targeted for cygwin

@samplefrequency

This comment has been minimized.

Show comment
Hide comment
@samplefrequency

samplefrequency Jun 12, 2017

@jmalczak I ended up simply overriding the PATH variable in WSL and everything is working well now.

samplefrequency commented Jun 12, 2017

@jmalczak I ended up simply overriding the PATH variable in WSL and everything is working well now.

@dacp

This comment has been minimized.

Show comment
Hide comment
@dacp

dacp Jul 15, 2017

Same, closing and re-opening fixed the issue.

dacp commented Jul 15, 2017

Same, closing and re-opening fixed the issue.

@deke997 deke997 referenced this issue Aug 18, 2017

Merged

Docs Update #973

@larscmagnusson

This comment has been minimized.

Show comment
Hide comment
@larscmagnusson

larscmagnusson Sep 5, 2017

alias npm="path-to-npm-bin-in"
in your .bash_rc works fine for me :)

larscmagnusson commented Sep 5, 2017

alias npm="path-to-npm-bin-in"
in your .bash_rc works fine for me :)

@Joseph211219479

This comment has been minimized.

Show comment
Hide comment
@Joseph211219479

Joseph211219479 Oct 13, 2017

from this post I : uninstalled node from windows, open bash as administer, reinstall node in bash. Thanks all above.

Joseph211219479 commented Oct 13, 2017

from this post I : uninstalled node from windows, open bash as administer, reinstall node in bash. Thanks all above.

@cenyG

This comment has been minimized.

Show comment
Hide comment
@cenyG

cenyG Aug 25, 2018

Use nvm for Ubuntu subsystem and all will be cool

cenyG commented Aug 25, 2018

Use nvm for Ubuntu subsystem and all will be cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment