node.js bash: npm: 在 Debian 9.3 中找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48943416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:42:12  来源:igfitidea点击:

bash: npm: command not found in Debian 9.3

node.jsnpmdebiandebian-stretch

提问by Orlando Cartagena

I am using Debian 9.3. (stretch) I cannot run "npm" commands.

我正在使用 Debian 9.3。(伸展)我无法运行“npm”命令。

Output for node -v

输出 node -v

bash: node: command not found

Output for nodejs -v

输出 nodejs -v

v4.8.2

Output for npm -v

输出 npm -v

bash: npm: command not found

I'm a newbie on Debian and I can't understand what's happening.
- I already reinstall Node.js
- I already tried following the steps of the Official Page.
- I already ran apt-get install npmOutput E: Unable to locate package npm.
- I was at Debian Testing and have the same error when I was there.

我是 Debian 的新手,我不明白发生了什么。
- 我已经重新安装了 Node.js
- 我已经按照官方页面的步骤尝试过。
- 我已经运行了apt-get install npmOutput E: Unable to locate package npm
- 我在 Debian 测试时遇到了同样的错误。

Thanks for read and help
- Melt

感谢阅读和帮助
- Melt

采纳答案by Diogo Jesus

Did you installed node js from their website? if that's not the case remove it apt-get remove nodejsand install it from this link (follow this steps) https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

您是否从他们的网站安装了 node js?如果不是这种情况,请删除它apt-get remove nodejs并从此链接安装它(按照此步骤操作) https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions



EDIT

编辑

After seing your version i realized that you are running an older version of nodejs... please remove the current nodejs version (V4.8.2) and install it via this link https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributionsIt will give you the last version (mine is V9.2.0) with NPM installed aswell.

看到您的版本后,我意识到您正在运行旧版本的 nodejs...请删除当前的 nodejs 版本(V4.8.2)并通过此链接进行安装https://nodejs.org/en/download/package-manager /#debian-and-ubuntu-based-linux-distributions它将为您提供安装了 NPM 的最新版本(我的是 V9.2.0)。

回答by TAHA SULTAN TEMURI

I had same problem with debian then I tried this and problem solved.

我在 debian 上遇到了同样的问题,然后我尝试了这个问题并解决了问题。

Run this is command

运行这是命令

curl -L https://npmjs.org/install.sh| sudo sh

curl -L https://npmjs.org/install.sh| 须藤

check version

检查版本

npm -v

npm -v

You should see this after doing these steps enter image description here

完成这些步骤后,您应该会看到这一点 在此处输入图片说明

回答by Mayfly

You got an old version of the package (append to me on debian 9)

你有一个旧版本的包(在 debian 9 上附加到我)

if you try : apt-cache show nodejsi think you will see the multiple version proposal.

如果您尝试:apt-cache show nodejs我想您会看到多版本提案。

just find the good repository name you want to use for your nodejs install :

只需找到要用于 nodejs 安装的好存储库名称:

Exemple for me it was :

以我为例,它是:

cat /etc/apt/sources.list.d/nodesource.list 
deb https://deb.nodesource.com/node_10.x stretch main
deb-src https://deb.nodesource.com/node_10.x stretch main

And force the use of stretch repository during install :

并在安装期间强制使用拉伸存储库:

sudo apt install -t stretch nodejs

since install is complete you got all the packages in the expected versions :

由于安装完成,您获得了预期版本中的所有软件包:

$ nodejs -v
v10.7.0
$ npm -v
6.1.0

回答by HOTAM SINGH

If nodejs -vshows version, it means nodejs is installed. you need to create soft link for node. Run below commands:

如果nodejs -v显示版本,则表示已安装 nodejs。您需要为节点创建软链接。运行以下命令:

sudo ln -s /usr/bin/nodejs /usr/bin/node

sudo ln -s /usr/bin/nodejs /usr/bin/node

And run

并运行

sudo apt-get install -y build-essential

sudo apt-get install -y build-essential

Now check node -vand npm -v. It will show version.

现在检查node -vnpm -v。它会显示版本。