sudo apt-get install npm
然后我得到这个:
The following packages have unmet dependencies:
npm : Depends: nodejs but it is not going to be installed
Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
Depends: node-ansi but it is not going to be installed
Depends: node-archy but it is not going to be installed
即使系统上存在 nodejs,我也应该单独安装每个依赖项,如何将它们安装在一起?
我也尝试过这个:
sudo apt-get install nodejs-dev
我得到了这个:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nodejs-dev : Depends: nodejs (= 0.10.25~dfsg2-2ubuntu1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
为什么系统上已经安装了 nodejs,它却提示不存在?如果它坏了,我该如何修复?我试过删除它然后重新安装,但没用,有什么办法吗?
编辑
npm:
Installed: (none)
Candidate: 1.3.10~dfsg-1
Version table:
1.3.10~dfsg-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
nodejs:
Installed: 4.2.1-2nodesource1~trusty1
Candidate: 4.2.1-2nodesource1~trusty1
Version table:
*** 4.2.1-2nodesource1~trusty1 0
500 https://deb.nodesource.com/node_4.x/ trusty/main amd64 Packages
100 /var/lib/dpkg/status
0.10.25~dfsg2-2ubuntu1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
node-abbrev:
Installed: 1.0.4-2
Candidate: 1.0.4-2
Version table:
*** 1.0.4-2 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
node-ansi:
Installed: 0.2.1-1
Candidate: 0.2.1-1
Version table:
*** 0.2.1-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
node-archy:
Installed: 0.0.2-1
Candidate: 0.0.2-1
Version table:
*** 0.0.2-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
答案1
首先我们尝试强制安装必要的软件包
sudo apt-get install node-abbrev node-ansi node-archy
sudo apt-get install --reinstall nodejs
apt-cache policy npm nodejs node-abbrev node-ansi node-archy
有了这个之后
npm:
Installed: (none)
Candidate: 1.3.10~dfsg-1
Version table:
1.3.10~dfsg-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
nodejs:
Installed: 4.2.1-2nodesource1~trusty1
Candidate: 4.2.1-2nodesource1~trusty1
Version table:
*** 4.2.1-2nodesource1~trusty1 0
500 https://deb.nodesource.com/node_4.x/ trusty/main amd64 Packages
100 /var/lib/dpkg/status
0.10.25~dfsg2-2ubuntu1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
node-abbrev:
Installed: 1.0.4-2
Candidate: 1.0.4-2
Version table:
*** 1.0.4-2 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
node-ansi:
Installed: 0.2.1-1
Candidate: 0.2.1-1
Version table:
*** 0.2.1-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
node-archy:
Installed: 0.0.2-1
Candidate: 0.0.2-1
Version table:
*** 0.0.2-1 0
500 http://kg.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
100 /var/lib/dpkg/status
由于我没有收到你的进一步反馈
sudo rm /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs=0.10.25~dfsg2-2ubuntu1
sudo apt-get install -f
sudo apt-get install npm