I can't use the npm command on Windows 10 with WSL2 ON (ubuntu terminal)

浪子不回头ぞ 提交于 2021-01-24 12:22:20

问题


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:

  1. 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.

  2. 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.

  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!