今天我决定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.
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能正确安装 npm 并再次运行?
谢谢。
kar*_*rel 29
关于 William Entriken 在这个答案下面的评论,有一种更好的方法可以在 Ubuntu 中本地安装 Node.js 作为 snap 包。
Node.js 在所有当前支持的 Ubuntu 版本中都可以作为 snap 包使用。特定于 Node.js,开发人员可以从一个或多个当前支持的版本中进行选择,并直接从 NodeSource 获取定期自动更新。Node.js 版本 6、8、9、10、11、13 和 14 目前可用,Snap Store 会在 Node.js 发布后的几小时或几分钟内更新。
可以使用单个命令安装节点,例如:
sudo snap install node --classic --channel 9/stable
Run Code Online (Sandbox Code Playgroud)
可以通过命令访问节点快照node
,例如:
$节点-v v9.9.0
最新版本的 npm 将作为 node snap 的一部分安装。npm 应该在节点 repl 之外的普通 shell 中运行。安装 node snap 后,运行以下命令以启用 npm 更新检查:
sudo 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
Run Code Online (Sandbox Code Playgroud)
用户可以测试 Node.js 的前沿版本,这些版本可以从当前跟踪 Node.js 版本 12 的最新边缘通道安装,方法是切换:
sudo snap switch node --edge
Run Code Online (Sandbox Code Playgroud)
这种方法只推荐给那些愿意参与上游测试和错误报告的用户。
要在所有当前支持的 Ubuntu 版本中安装 Node.js (nodejs) 的最新 LTS 版本和 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
Run Code Online (Sandbox Code Playgroud)
如果您要复制这三个命令,请不要忽略第二个命令末尾的连字符。
该nodejs
软件包包含nodejs
二进制文件以及npm
,因此您无需npm
单独安装。但是,为了使某些npm
包正常工作(例如需要从源代码构建的build-essential
包),您需要安装该包:
sudo apt-get install build-essential
Run Code Online (Sandbox Code Playgroud)
Node.js 的新 semver-major 版本从master
每六个月开始减少。新的偶数版本(例如 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
Run Code Online (Sandbox Code Playgroud)
发布 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 无 LTS 2019-04-01 2019-06-30 12.x 2019-10-22 2021-04-01 2022-04-01 13.x 无 LTS 2020-04-20 2020-06-01 14.x 当前 Fermium 2020-10-20 2021-10-20 2023-04-30
归档时间: |
|
查看次数: |
24801 次 |
最近记录: |