解决方案

解决方案

我尝试在 Ubuntu 22.04.2LTS 上安装 NodeJS 版本 14,但弹出此错误

dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)

如果有人需要的话,这是完整的日志:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp javascript-common libdevmapper1.02.1:i386 libefiboot1:i386
  libefivar1:i386 libjs-events libjs-highlight.js libjs-inherits
  libjs-is-typedarray libjs-psl libjs-source-map libjs-sprintf-js
  libjs-typedarray-to-buffer libnode-dev libnode72 libssl-dev libuv1-dev
  node-abbrev node-ansi-regex node-ansi-styles node-ansistyles
  node-are-we-there-yet node-arrify node-asap node-asynckit
  node-balanced-match node-brace-expansion node-chownr node-clean-yaml-object
  node-color-convert node-color-name node-commander node-core-util-is
  node-decompress-response node-delayed-stream node-delegates node-depd
  node-diff node-encoding node-end-of-stream node-err-code
  node-escape-string-regexp node-fancy-log node-foreground-child
  node-fs.realpath node-function-bind node-get-stream node-glob node-growl
  node-has-flag node-has-unicode node-hosted-git-info node-iconv-lite
  node-iferr node-imurmurhash node-indent-string node-inflight node-inherits
  node-ini node-ip node-ip-regex node-is-buffer node-is-plain-obj
  node-is-typedarray node-isarray node-isexe node-json-parse-better-errors
  node-jsonparse node-kind-of node-lodash-packages node-lowercase-keys
  node-lru-cache node-mimic-response node-minimatch node-minimist
  node-minipass node-mute-stream node-negotiator node-npm-bundled node-once
  node-osenv node-p-cancelable node-p-map node-path-is-absolute
  node-process-nextick-args node-promise-inflight node-promise-retry
  node-promzard node-pump node-quick-lru node-read node-readable-stream
  node-resolve node-retry node-safe-buffer node-set-blocking node-signal-exit
  node-slash node-slice-ansi node-source-map node-spdx-correct
  node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids
  node-sprintf-js node-stealthy-require node-string-decoder
  node-supports-color node-text-table node-time-stamp node-tmatch
  node-typedarray-to-buffer node-universalify node-util-deprecate
  node-validate-npm-package-license node-webidl-conversions node-whatwg-fetch
  node-wrappy node-yallist
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 114 not upgraded.
Need to get 0 B/25.4 MB of archives.
After this operation, 121 MB of additional disk space will be used.
(Reading database ... 255398 files and directories currently installed.)
Preparing to unpack .../nodejs_14.21.3-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (14.21.3-deb-1nodesource1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_14.21.3-deb-1nodes
ource1_amd64.deb (--unpack):
 trying to overwrite '/usr/include/node/common.gypi', which is also in package l
ibnode-dev 12.22.9~dfsg-1ubuntu3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_14.21.3-deb-1nodesource1_amd64.deb```

答案1

解决方案

安装 node 时,我强烈建议使用 nvm(Node 版本管理器)进行安装。这样可以轻松使用关联的 npm 从 node 安装某个版本。它还可以非常轻松地在 node 版本之间进行切换。

安装 nvm

您可以在这里找到 nvm:https://github.com/nvm-sh/nvm

跑步: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

这将在您的主目录中创建一个 .nvm 目录并尝试更新您的 .bashrc。

如果您不使用 bash,请参阅文档,几乎所有内容都受支持。

使用 nvm 安装节点

重新打开您的终端,以便使用 nvm 脚本。

安装你的节点版本:
nvm install 14

选择您的节点版本:
nvm use 14

如果您想检查特定版本运行:
nvm ls-remote

节点已安装

现在,您的 node 版本已与其关联的 npm 版本一起安装。每个 node 版本都有自己的 node_modules。这意味着全局安装的 npm 包仅适用于您安装它的 node 版本。

如果您想在节点版本之间切换,只需安装一个新版本,然后nvm install lts使用 进行切换nvm use lts

如果您需要更多信息,请务必查看其 github 上的 README.md。

相关内容