Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
WSL prefers NodeJS executable in Program Files over /usr/bin #1896
I've just tried installing NodeJS on WSL, after running the Creators Update and doing a fresh WSL install to get 16.04.
Running node works fine:
But npm doesn't work:
It seems to be trying to run the npm executable from Windows. I tried some other things:
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.
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?
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.
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.
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.
changed the title from
WSL prefers executable in Program Files over /usr/bin
WSL prefers executable in Program Files over /usr/bin (NodeJS)
Apr 15, 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.