无法正确安装nodejs和npm?

无法正确安装nodejs和npm?

我想安装 nodejs 它的 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 (>= 0.3.0-2) but it is not going to be installed
   Depends: node-ansi-color-table 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 (>= 3.0.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-underscore but it is not going to be installed
   Depends: node-which but it is not going to be installed

请有人帮助正确安装。

答案1

Node.js 软件包有两个版本: LTS 版本当前版本。您可以安装任何您想要的版本。我正在为这个答案安装 LTS 版本。

  1. 添加 Node.js PPA

您需要curl下载脚本,因此首先curl通过输入sudo apt install curl进行安装terminal

安装成功后curl,运行命令下载并安装安装程序。

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
  1. 安装nodejs

现在,使用 运行以下命令在 Ubuntu 上安装节点apt。此命令也将npm使用进行安装nodejs。它还将安装依赖项。

sudo apt install nodejs

node注意:要检查运行命令的版本

node -v 

npm要检查运行命令的版本

npm -v 

答案2

只需删除 nodejs

sudo apt-get remove node restart machine 并再次安装。对我来说很管用。

答案3

嗨,关注这个这里链接安装 nodejs、NPM、NVM。对于 UBUNTU 相关文档,Digital Ocean 有很好的文档,它会引导您完成每个命令。

希望这有帮助。

相关内容