无法在 ubuntu 上安装 npm

use*_*351 43 package-management nodejs npm

尝试在 ubuntu 12.04 上安装 nodejs 和 npm。我用谷歌搜索并做到了。现在,我无法在机器上安装 npm。

sudo apt-get install npm
Run Code Online (Sandbox Code Playgroud)

这给了我这个

The following packages have unmet dependencies:
 npm : Depends: nodejs but it is not going to be installed
       Depends: nodejs-dev
       Depends: node-request but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-minimatch but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ini but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-abbrev but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-fstream but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-tar 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)

Mar*_*ppi 39

看起来您可能安装了chris-lea node.js ppa,这很好。但是,您不要从该 ppa 安装 npm,因为它破坏了 debian 软件包的工作方式。相反,只需安装nodejs. 安装完成后,运行npm -v您应该看到它现在已安装。如果您没有使用 chris-lea ppa,请在您通过 Google 搜索的网页上更新您的问题,以了解如何在 Ubuntu 上安装 nodejs。

  • “现代”`apt-get install nodejs` 也进行`npm` 更新安装,所以,我知道必须避免使用`apt-get install npm`(!)。 (11认同)
  • 如果他不能安装 npm...,他将如何运行“npm -v”? (8认同)

Mar*_*raz 7

尝试像这样安装 NodeJ:

sudo apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)

由于 NodeJs 安装了 node 和 npm

  • 不适用于 16.04 (2认同)

use*_*351 1

我按照此文档解决了这个问题。

使用 npm 时需要记住的提示:

mkdir ~/nodejs/ && cd ~/nodejs
sudo apt-get install npm
npm install
npm update
Run Code Online (Sandbox Code Playgroud)

在开发应用程序时,如果nodejs需要任何特定模块,则运行

cd ~/nodejs
npm install modulename   #for example sendgrid
Run Code Online (Sandbox Code Playgroud)

有时,模块需要全局安装;然后使用

sudo npm install modulename -g"
Run Code Online (Sandbox Code Playgroud)

要删除模块:

cd ~/nodejs
npm uninstall modulename          # if locally installed or 
sudo npm uninstall modulename -g  # if globally installed
Run Code Online (Sandbox Code Playgroud)

npm prune有助于消除未满足的依赖关系

  • 他无法安装 npm men,他怎么能到达第 3 点?! (4认同)