问题
I'm trying to get the npm command to work but it doesn't want to. As i said in the title, I'm using the windows WSL2. I already have installed nodejs with Git Bash a long time ago but now I need it to work on my ubuntu terminal. How could I fix this issue?
My ubuntu terminal:
root@DESKTOP-U2RC2DU:~# node -v v10.19.0 root@DESKTOP-U2RC2DU:~# npm -bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory root@DESKTOP-U2RC2DU:~#
回答1:
Check your path in WSL. If the Windows version is found before the Linux version, it can cause problems.
There are a few possible workarounds for this that I know of:
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.
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.
If you don't need it anymore, and will be using the Linux/WSL version exclusively, you could uninstall the Windows nodejs.
来源:https://stackoverflow.com/questions/63116206/i-cant-use-the-npm-command-on-windows-10-with-wsl2-on-ubuntu-terminal