尝试覆盖'/usr/share/man/man1/node.1.gz',该文件也存在于nodejs-legacy 0.10.25~dfsg2-2ubuntu1软件包中。

我正在尝试安装nodejs,但是一直失败。附上日志。
$ sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libc-ares2 libv8-3.14.5
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  rlwrap
The following NEW packages will be installed:
  rlwrap
The following packages will be upgraded:
  nodejs
1 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 0 B/4,391 kB of archives.
After this operation, 14.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package rlwrap.
(Reading database ... 263979 files and directories currently installed.)
Preparing to unpack .../rlwrap_0.37-5_amd64.deb ...
Unpacking rlwrap (0.37-5) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_0.10.31-1chl1~trusty1_amd64.deb ...
Unpacking nodejs (0.10.31-1chl1~trusty1) over (0.10.25~dfsg2-2ubuntu1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_0.10.31-1chl1~trusty1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/man/man1/node.1.gz', which is also in package nodejs-legacy 0.10.25~dfsg2-2ubuntu1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Processing triggers for man-db (2.6.7.1-1) ...
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_0.10.31-1chl1~trusty1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

你能运行 sudo apt-get updatesudo apt-get upgrade 吗? - Charles Green
@CharlesGreen 我已经解决了问题,成功让它运作起来了。我自己给出了答案。 - Shash
2个回答

可能修复安装问题

正如查尔斯在评论中所说,我建议尝试运行sudo apt-get updatesudo apt-get upgrade。您还可以运行sudo apt-get autoremove来删除不再需要的软件包。

错误提到了nodejs-legacy软件包。如果您曾经安装过它,您可能希望将其删除。

在Ubuntu上安装Node.js的更好方法

除非您计划将计算机用作生产服务器,否则我强烈建议使用NVM工具安装Node.js。从存储库安装需要使用sudo,这会导致使用NPM安装Node模块时出现混乱的权限问题

作为额外的好处,NVM允许您安装多个版本的Node,并且即使官方存储库落后,也可以保持您的Node副本最新。

获取最新的NVM副本

curl https://raw.githubusercontent.com/creationix/nvm/v0.15.0/install.sh | bash

告诉你的命令行使用 nvm
source ~/.nvm/nvm.sh

然后安装一个Node版本。
nvm install 0.10

告诉 nvm 你想要使用的 Node 版本
nvm use 0.10

1谢谢你。告诉我关于nvm的事情真的帮助了我。我已经厌倦了权限的斗争。 - Chev
你还可以通过在~/.npmrc中更新前缀路径来解决权限问题,这样你就可以指向你的主目录。 - rich remer

有一件事我忘了做,那就是清除之前的安装然后重新安装。我使用了以下命令来移除之前的安装。
sudo apt-get purge nodejs-legacy nodejs

sudo apt-get install nodejs

重新安装Node.js。

这个Stack Overflow答案帮助了我


啊,在我还没打完字之前你就想到了!:) 不过,我仍然建议你了解一下 NVM,这样你就可以避免每次想要使用 npm 安装模块时都要执行 sudo npm install - Michael Martin-Smucker