我已经安装了nodejs
:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
安装完成并且当我尝试安装npm
时sudo apt-get install npm
我收到了这个输出:
Reading package lists... Done
Building dependency tree
Reading state information... Done
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:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
我该怎么办?
修改:
当我运行npm --version
时,输出如下:
The program 'npm' is currently not installed. You can install it by typing:
sudo apt install npm
答案 0 :(得分:11)
TL; DR
nodejs
需要libssl1.0-dev
,如果已经安装libcurl4-openssl-dev
或libssl-dev
,则无法安装。
解决方案是卸载libcurl4-openssl-dev
和libssl-dev
,或者安装libssl1.0-dev
强制删除其他对象。
全文
我遇到了同样的问题,所以我尝试手动安装它抱怨的每个软件包。
$ sudo apt install npm
...
The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
$ sudo apt install node-gyp
...
The following packages have unmet dependencies:
node-gyp : Depends: nodejs-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
$ sudo apt install nodejs-dev
...
The following packages have unmet dependencies:
nodejs-dev : Depends: libssl1.0-dev (>= 1.0.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
$ sudo apt install libssl1.0-dev
...
The following packages will be REMOVED:
libcurl4-openssl-dev libssl-dev
The following NEW packages will be installed:
libssl1.0-dev
0 to upgrade, 1 to newly install, 2 to remove and 0 not to upgrade.
Need to get 1,364 kB of archives.
After this operation, 1,017 kB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://au.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl1.0-dev amd64 1.0.2n-1ubuntu5.1 [1,364 kB]
Fetched 1,364 kB in 4s (368 kB/s)
(Reading database ... 323301 files and directories currently installed.)
Removing libcurl4-openssl-dev:amd64 (7.58.0-2ubuntu3.3) ...
Removing libssl-dev:amd64 (1.1.0g-2ubuntu4.1) ...
Selecting previously unselected package libssl1.0-dev:amd64.
(Reading database ... 323196 files and directories currently installed.)
Preparing to unpack .../libssl1.0-dev_1.0.2n-1ubuntu5.1_amd64.deb ...
Unpacking libssl1.0-dev:amd64 (1.0.2n-1ubuntu5.1) ...
Setting up libssl1.0-dev:amd64 (1.0.2n-1ubuntu5.1) ...
Processing triggers for man-db (2.8.3-2) ...
e voila:
$ sudo apt install npm
...
The following additional packages will be installed:
gyp libc-ares2 libhttp-parser2.7.1 libjs-async libjs-inherits libjs-node-uuid libuv1 libuv1-dev node-abbrev node-ansi node-ansi-color-table node-archy node-async node-balanced-match node-block-stream
node-brace-expansion node-builtin-modules node-combined-stream node-concat-map node-cookie-jar node-delayed-stream node-forever-agent node-form-data node-fs.realpath node-fstream node-fstream-ignore
node-github-url-from-git node-glob node-graceful-fs node-gyp node-hosted-git-info node-inflight node-inherits node-ini node-is-builtin-module node-isexe node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once node-osenv node-path-is-absolute node-pseudomap node-qs
node-read node-read-package-json node-request node-retry node-rimraf node-semver node-sha node-slide node-spdx-correct node-spdx-expression-parse node-spdx-license-ids node-tar node-tunnel-agent
node-underscore node-validate-npm-package-license node-which node-wrappy node-yallist nodejs nodejs-dev nodejs-doc
Suggested packages:
node-hawk node-aws-sign node-oauth-sign node-http-signature
The following NEW packages will be installed:
gyp libc-ares2 libhttp-parser2.7.1 libjs-async libjs-inherits libjs-node-uuid libuv1 libuv1-dev node-abbrev node-ansi node-ansi-color-table node-archy node-async node-balanced-match node-block-stream
node-brace-expansion node-builtin-modules node-combined-stream node-concat-map node-cookie-jar node-delayed-stream node-forever-agent node-form-data node-fs.realpath node-fstream node-fstream-ignore
node-github-url-from-git node-glob node-graceful-fs node-gyp node-hosted-git-info node-inflight node-inherits node-ini node-is-builtin-module node-isexe node-json-stringify-safe node-lockfile
node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once node-osenv node-path-is-absolute node-pseudomap node-qs
node-read node-read-package-json node-request node-retry node-rimraf node-semver node-sha node-slide node-spdx-correct node-spdx-expression-parse node-spdx-license-ids node-tar node-tunnel-agent
node-underscore node-validate-npm-package-license node-which node-wrappy node-yallist nodejs nodejs-dev nodejs-doc npm
0 to upgrade, 74 to newly install, 0 to remove and 0 not to upgrade.
Need to get 8,422 kB of archives.
After this operation, 40.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
答案 1 :(得分:1)
你能检查一下你的系统上是否有npm吗? 如果是这样更新它。这可能有用。
npm -v
sudo npm install npm@latest -g
好的,我在你编辑的帖子中看到npm不存在。 我建议您快速更新您的Ubuntu系统
sudo apt-get update && sudo apt-get -y upgrade
然后再次安装节点
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
注意,上面的命令适用于节点版本9,但如果需要,请将其替换为8.
答案 2 :(得分:1)
这是一个古老的问题,但是对于仍然关注该问题的任何人,这是一个使用Ubuntu来启动并运行最新版本的节点的很好的指南:
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04
该指南涵盖了PPA的安装,或者,如果您对在Ubuntu安装中添加非官方的仓库过敏,还可以告诉您如何下载和运行nvm,这将极大地增加您选择在/ home目录中运行的任何版本的节点的本地实例。
答案 3 :(得分:1)
我遇到了同样的问题,我通过添加 nodesource repo 解决了这个问题
sudo curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install nodejs
答案 4 :(得分:0)
如果安装了nodejs,则还会出现npm。
在控制台中尝试以下操作:
switch indexPath.row {
case 0:
doButton()
case 1:
/// do something else
default:
// break
}
或node --version
答案 5 :(得分:0)
错误是:
E: Unable to correct problems, you have held broken packages.
您可以输入以下内容来检查所持有的包裹:
apt-mark showhold
哪一个在那里,不知道它:
sudo apt-mark unhold <package name>
然后重新安装nodejs。
如果不这样做,你可以尝试用aptitude安装npm - 它比apt-get更能修复依赖项。
sudo aptitude install npm
如果您没有安装aptitude,可以使用
进行安装sudo apt install aptitude
答案 6 :(得分:0)
复制到/usr/
:
sudo cp -r node/{bin,include,lib,share} /usr/