在 WSL2 中:安装了适用于 Windows 10 nodejs 的 Ubuntu 20.04,但 npm 不工作 [英] In WSL2: Ubuntu 20.04 for Windows 10 nodejs is installed but npm is not working

查看:40
本文介绍了在 WSL2 中:安装了适用于 Windows 10 nodejs 的 Ubuntu 20.04,但 npm 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 10 操作系统中使用 WSL2: Ubuntu 20.04.当我执行 node -v 命令时,我使用命令 sudo apt-get install -y nodejs 安装了 nodejs,我得到 v12.18.3

<上一页>mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ 节点 -vv12.18.3

但是当我执行 npm -v 命令时,我得到以下命令

<上一页>mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ npm -v-bash:/mnt/c/Program Files/nodejs/npm:/bin/sh^M: 错误的解释器:没有这样的文件或目录

我也做 whereis 命令.希望这将有助于找到解决方案.

<上一页>mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ whereis 节点节点:/usr/bin/node/usr/include/node/mnt/c/Program Files/nodejs/node.exe/usr/share/man/man1/node.1.gzmrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ whereis npmnpm:/usr/bin/npm/mnt/c/Program Files/nodejs/npm/mnt/c/Program Files/nodejs/npm.cmd/usr/share/man/man1/npm.1

我已经尝试了几乎所有的 stackoverflow 解决方案和 github 问题,但对我没有任何帮助.
希望任何善良的灵魂都能解决这个问题.提前致谢.

解决方案

试试这个

导出路径=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binsudo apt 安装 npm

I am using WSL2: Ubuntu 20.04 in my Windows 10 operating system. I have installed nodejs using the command sudo apt-get install -y nodejs when I do node -v command I get v12.18.3

mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ node -v
v12.18.3

but when I do npm -v command I get this below command

mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ npm -v
-bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory

I also do whereis command. Hope this will help to find solution.

mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ whereis node
node: /usr/bin/node /usr/include/node /mnt/c/Program Files/nodejs/node.exe /usr/share/man/man1/node.1.gz

mrd@DESKTOP-2EO5K4H:/mnt/c/Users/musfi$ whereis npm
npm: /usr/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd /usr/share/man/man1/npm.1

I have tried almost all the stackoverflow solutions and github issues but nothing is worked for me.
Hope any kind soul has the solution to this problem. Thanks in advance.

解决方案

Try this

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sudo apt install npm

这篇关于在 WSL2 中:安装了适用于 Windows 10 nodejs 的 Ubuntu 20.04,但 npm 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆