bash 安装 NPM 和 NodeJS 的正确方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28275226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the proper way to install NPM and NodeJS?
提问by fizrock
What is the proper way to install NPM and NodeJS ?
安装 NPM 和 NodeJS 的正确方法是什么?
Method 1 .: sudo apt-get install npm
方法一。: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.
======================================================================
Method 2.curl -L https://npmjs.com/install.sh | sh
================================================== ====================
方法二。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 [email protected]
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
> [email protected] 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
In Both cases i was unable to get install npm please guide me thanks
在这两种情况下我都无法安装 npm 请指导我谢谢
回答by Philipp Smirnov
NVM should be used.
应该使用 NVM。
First run
第一次运行
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.1/install.sh | bash
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.1/install.sh | bash
After
后
nvm install 0.12
This will provide you with working node. If you want to know more about other advantages of nvm - read more at https://github.com/creationix/nvm
这将为您提供工作节点。如果您想了解更多关于 nvm 的其他优势 - 在https://github.com/creationix/nvm阅读更多信息
回答by NooBskie
Since i cant comment yet..
因为我还不能评论..
you need to run method 2 as root
thats why your getting EACCES
errors
您需要运行方法 2,因为root
这就是您收到EACCES
错误的原因
sudo curl -L https://npmjs.com/install.sh | sudo sh
sudo curl -L https://npmjs.com/install.sh | sudo sh