今天,当我决定npm update -g
在nodejs应用程序目录中使用时遇到了一个问题。这是一个错误的决定,因为它使我遇到了npm常见而灾难性的问题。
解决方案是重新安装nodejs和npm。不幸的是,当我使用sudo apt-get install npm
它安装npm时不起作用。
终端中的完整错误在这里:
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: 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
Depends: node-block-stream but it is not going to be installed
Depends: node-fstream (>= 0.1.22) but it is not going to be installed
Depends: node-fstream-ignore but it is not going to be installed
Depends: node-github-url-from-git but it is not going to be installed
Depends: node-glob (>= 3.1.21) but it is not going to be installed
Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
Depends: node-inherits but it is not going to be installed
Depends: node-ini (>= 1.1.0) but it is not going to be installed
Depends: node-lockfile but it is not going to be installed
Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
Depends: node-gyp (>= 0.10.9) but it is not going to be installed
Depends: node-nopt (>= 2.1.1) but it is not going to be installed
Depends: node-npmlog but it is not going to be installed
Depends: node-once but it is not going to be installed
Depends: node-osenv but it is not going to be installed
Depends: node-read but it is not going to be installed
Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
Depends: node-request (>= 2.25.0) but it is not going to be installed
Depends: node-retry but it is not going to be installed
Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
Depends: node-semver (>= 2.1.0) but it is not going to be installed
Depends: node-sha but it is not going to be installed
Depends: node-slide but it is not going to be installed
Depends: node-tar (>= 0.1.18) but it is not going to be installed
Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
如何正确安装npm并再次运行?
谢谢。
关于此答案下方的William Entriken的评论,有一种更好的方法可以在Ubuntu上以本机软件包形式安装Node.js。
在当前所有受支持的Ubuntu版本中,Node.js均作为快照包提供。特定于Node.js的开发人员可以从一个或多个当前受支持的版本中进行选择,并直接从NodeSource获得定期的自动更新。Node.js版本6、8、9、10、11、13和14当前可用,并且Snap Store在Node.js版本发布后的数小时或数分钟内进行了更新。
可以使用单个命令来安装节点,例如:
sudo snap install node --classic --channel 9/stable
可以通过以下命令访问节点快照node
,例如:
$ node -v v9.9.0
作为节点快照的一部分,将安装npm的最新版本。npm应该在常规外壳中的节点repl外部运行。安装节点快照后,运行以下命令以启用npm更新检查:
须藤chown -R $ USER:$ {id -gn $ USER)/ home /您的用户名/.config
your-username
用您自己的用户名替换上述命令。然后运行npm -v
以检查npm的版本是否为最新。例如,我检查npm是最新的,使用命令检查已经安装的名为yarn的软件包的版本,npm list yarn
然后使用命令将现有的yarn软件包更新为最新版本。npm update yarn
用户可以随时在Node.js版本之间切换,而无需使用其他工具,例如nvm(节点版本管理器),例如:
sudo snap refresh node --channel=8/stable
用户可以通过以下方式测试可以从最新边缘通道安装的最新版本的Node.js:该边缘通道当前正在跟踪Node.js版本12:
sudo snap switch node --edge
仅建议那些愿意参与上游测试和错误报告的用户使用此方法。
要在所有当前受支持的Ubuntu版本中安装最新的LTS版本的Node.js(nodejs)和用于Node.js的程序包管理器(npm),请打开终端并运行以下命令:
sudo apt-get remove nodejs npm ## remove existing nodejs and npm packages
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
如果要复制这三个命令,请不要在第二个命令的末尾忽略连字符。
该nodejs
软件包包含以及nodejs
二进制文件npm
,因此您无需npm
单独安装。但是,为了使某些npm
软件包(例如那些需要从源代码构建的软件包)起作用,您将需要安装该build-essential
软件包:
sudo apt-get install build-essential
master
每六个月就会减少Node.js的主要新版本。新的偶数版本(例如v6,v8,v10等)在4月被削减。新的奇数版本(例如v5,v7,v9)在10月被削减。
剪切新的奇数主版本后,以前的偶数主版本将过渡到“长期支持”计划。
LTS计划涵盖的每个主要版本将从进入LTS覆盖之日起有效维护18个月。在这18个月的积极支持之后,主要版本将过渡到“维护”模式另外12个月。
当前到2017年3月,用于安装最新的非LTS版本的Node.js(发布时为v8)的命令如下:
sudo apt-get remove nodejs npm ## remove existing nodejs and npm packages
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
发布LTS状态代号LTS开始维护开始维护结束 6.x活性硼2016-10-18 2018年4月2019年4月 7.x否LTS 8.x活性碳2017-10-31 2019年4月2019年12月 9.x否LTS 10。 x Active Dubnium 2018年10月2020年4月2021年4月 11.x No LTS 2019-04-01 2019-06-30 12.x 2019-10-22 2021-04-01 2022-04-01 13.x No LTS 2020-04 -20 2020-06-01 14.x当前的m 2020-10-20 2021-10-20 2023-04-30
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句