在安装/升级nodejs v0.10.30时出现“update-alternatives”错误

所以我在进行apt-get升级时遇到这个错误

Setting up nodejs (0.10.30-1chl1~trusty1) ... update-alternatives: error: alternative link /usr/bin/node is already managed by nodejs dpkg: error processing package nodejs (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: nodejs E: Sub-process /usr/bin/dpkg returned an error code (1) 

NB:“nodejs –version”的作品,我得到一个干净的“v0.10.30”,但“节点 – 版本”没有,因为没有链接。

到目前为止,我已经尝试过:

  • 完全删除nodejs和新的安装
  • 在删除nodejs之后,我手动删除了链接/ usr / bin / node到nodejs,因为它仍然存在,并且问题与update-alternatives有关
  • 使用“update-alternatives –config nodesjs”(我第一次使用它时被破坏和修复,但没有解决问题,因为这个错误没有出现)。

其他答案没有解决我的设置上的问题,也许是因为我使用的是NodeSource存储库,而不是官方的。

但是我只是首先删除了nodejs组的所有“选项”:

 sudo update-alternatives --remove-all nodejs 

之后, sudo apt-get install nodejs刚刚工作。

可能你已经安装了旧版本的NodeJS,升级时会出现冲突。

唯一使用/usr/bin/node软件包是nodejs-legacy ,所以除非你自己创build了这个链接,或者从你需要删除的软件包源代码中安装了NodeJS:

 $ sudo apt-get purge nodejs-legacy nodejs 

之后,只需重新安装NodeJS,更新和升级您的软件:

 $ sudo apt-get install nodejs $ sudo apt-get update && sudo apt-get upgrade 

从输出中,您从PPA获得的NodeJS版本优先于其他版本,因此安装它时不会有任何问题。

我真的鼓励你使用nvm在你的Ubuntu机器上安装Node.js( https://github.com/creationix/nvm )。 这样,任何Node.js版本的安装变得非常容易。