由于与其他包名称冲突,Ubuntu上的NodeJS解释器名称(node)被重命名为NodeJS。这是自述。Debian说:

node .js解释器命令的上游名称是“node”。 在Debian中,解释器命令已更改为"nodejs"。 这样做是为了防止名称空间冲突:使用其他命令 在其上游相同的名称,如ax25-node中的“node” 包中。 作为shell命令调用Node.js的脚本必须改为 使用“nodejs”命令。

然而,使用nodejs会搞砸使用npm安装包的过程。软件包安装失败,报错如下:

Sh: 1: node: not found 此失败可能是由于使用了遗留的二进制"node" 更多解释请阅读/usr/share/doc/nodejs/ readmeDebian

我如何让npm理解nodejs已经安装在系统上,但解释器名称不同?


当前回答

对我来说,修复是删除node*包和npm包。

然后重新安装如下:

sudo apt-get install autoclean
sudo apt-get install nodejs-legacy
npm install

其他回答

可以在/usr/bin中创建link ln -s nodejs节点 希望这能解决你的问题。

在Linux Mint 17上,我尝试了两种解决方案(创建符号链接或使用nodejs-legacy包)都没有成功。

唯一对我有用的是使用Chris Lea的ppa:

sudo apt-get purge node-*
sudo apt-get autoremove 
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

此安装的节点版本为10.37和npm 1.4.28。在那之后,我可以在全球范围内安装包。

尝试将node链接到nodejs。首先找出nodejs在哪里

whereis nodejs

然后将节点软链接到nodejs

ln -s [the path of nodejs] /usr/bin/node 

我假设/usr/bin在您的执行路径中。然后你可以在命令行中输入node或npm进行测试,现在一切都可以工作了。

面对同样的问题,下面的步骤对我有用。

在系统上安装curl,然后运行NVM安装程序脚本。

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

加载环境

source ~/.profile 

安装Node.js支持的版本。

nvm install 16.15.1

安装确认

node -v

Install nvm first using: curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash Run command source ~/.profile Now run this and this will show will all installed or other versions of packages: nvm ls-remote Installed packages will be in green. Install whatever version you want: nvm install 6.0.0 Check where is not installed: which node Check current version: node -v n=$(which node); n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local