安装NPM和NodeJS的正确方法是什么?
方法1。:sudo apt-get install npm
sudo apt-get install npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
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.
=============================================== =======================
方法2。 curl -L https://npmjs.com/install.sh | sh
curl -L https://npmjs.com/install.sh | sh % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 132 0 0:00:01 0:00:01 --:--:-- 132
100 6239 100 6239 0 0 1976 0 0:00:03 0:00:03 --:--:-- 6986
tar=/bin/tar
version:
tar (GNU tar) 1.27.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason.
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-2.4.1.tgz
unbuild npm@2.5.0
npm ERR! Linux 3.13.0-44-generic
npm ERR! argv "/usr/bin/node" "/tmp/npm.14799/package/cli.js" "rm" "npm" "-gf"
npm ERR! node v0.10.36
npm ERR! npm v2.4.1
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! Error: EACCES, unlink '/usr/bin/npm'
npm ERR! { [Error: EACCES, unlink '/usr/bin/npm'] errno: 3, code: 'EACCES', path: '/usr/bin/npm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/npm.14799/package/npm-debug.log
> npm@2.4.1 prepublish /tmp/npm.14799/package
> node bin/npm-cli.js prune --prefix=. --no-global && rm -rf test/*/*/node_modules && make -j8 doc
make: Nothing to be done for `doc'.
npm ERR! Linux 3.13.0-44-generic
npm ERR! argv "/usr/bin/node" "/tmp/npm.14799/package/cli.js" "install" "-gf"
npm ERR! node v0.10.36
npm ERR! npm v2.4.1
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! Error: EACCES, unlink '/usr/bin/npm'
npm ERR! { [Error: EACCES, unlink '/usr/bin/npm'] errno: 3, code: 'EACCES', path: '/usr/bin/npm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, unlink '/usr/bin/npm'
npm ERR! error rolling back { [Error: EACCES, unlink '/usr/bin/npm'] errno: 3, code: 'EACCES', path: '/usr/bin/npm' }
npm ERR! Please include the following file with any support request:
npm ERR! /tmp/npm.14799/package/npm-debug.log
It failed
在这两种情况下我都无法安装npm请指导我谢谢
答案 0 :(得分:5)
应该使用NVM。
首次运行
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.1/install.sh | bash
之后
nvm install 0.12
这将为您提供工作节点。如果您想进一步了解nvm的其他优点 - 请在https://github.com/creationix/nvm
了解更多信息答案 1 :(得分:-1)
因为我还没有发表评论..
您需要将方法2作为root
运行,这就是您收到EACCES
错误的原因
sudo curl -L https://npmjs.com/install.sh | sudo sh