尝试在 ubuntu 12.04 上安装 nodejs 和 npm。我用 Google 搜索并成功了。现在,我无法在机器上安装 npm。
sudo apt-get install npm
这给了我这个
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.
答案1
看起来你可能安装了chris-lea node.js ppa这没问题。但是,您不能从该 ppa 安装 npm,因为它会破坏 debian 软件包的工作方式。相反,只需安装nodejs
。安装完成后,运行npm -v
您应该会看到它现在已安装。如果您没有使用 chris-lea ppa 更新,您的问题与您在 Google 上搜索如何在 Ubuntu 上安装 nodejs 的网页有关。
答案2
尝试像这样安装 NodeJs:
sudo apt-get install nodejs
由于 NodeJs 安装了 node 和 npm
答案3
Apt 不能很好地处理依赖冲突,请使用 snap 或 aptitude;
sudo aptitude install npm
我不得不对它提出的第一个解决方案按“否”,其中不包括安装 npm(这一定是 aptitude 中的一个错误),然后我按下第二个解决方案yes
来检查 npm 是否已安装:
npm --version
答案4
我通过以下方式解决了这个问题本文档。
使用 npm 时需要记住的要点:
mkdir ~/nodejs/ && cd ~/nodejs
sudo apt-get install npm
npm install
npm update
在开发应用程序时,如果 nodejs 需要任何特定模块,则运行
cd ~/nodejs
npm install modulename #for example sendgrid
有时,模块需要全局安装;然后使用
sudo npm install modulename -g"
要删除模块:
cd ~/nodejs
npm uninstall modulename # if locally installed or
sudo npm uninstall modulename -g # if globally installed
npm prune
帮助消除未满足的依赖关系