由于与其他包名称冲突,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已经安装在系统上,但解释器名称不同?


当前回答

可以在/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。在那之后,我可以在全球范围内安装包。

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs

sudo apt-get install nodejs-legacy
source ~/.profile

将接受的答案与源~/结合起来。概要文件来自已折叠的注释和一些清理命令之前。很可能你还需要sudo apt-get install npm after。

卸载您拥有的任何节点版本

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs

安装nvm(节点版本管理器)https://github.com/creationix/nvm

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

现在您可以安装您想要的任何版本的节点,并在版本之间进行切换。

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

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