nodejs npm 安装错误

nodejs npm 安装错误

我使用 root 权限执行此操作。但仍然收到拒绝访问错误。

hrishikesh@hrishikesh-ubuntu:~$ sudo curl http://npmjs.org/install.sh | sh
[sudo] password for hrishikesh: 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7881  100  7881    0     0  12574      0 --:--:-- --:--:-- --:--:-- 37174
tar=/bin/tar
version:
tar (GNU tar) 1.25
Copyright (C) 2010 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 [email protected]
fetching: http://registry.npmjs.org/npm/-/npm-1.1.1.tgz
0.6.10
1.1.1
cleanup prefix=/usr/local

All clean!

npm ERR! Error: EACCES, permission denied '/usr/local/bin/npm'
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! 
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "/usr/local/bin/node" "/tmp/npm.2959/package/cli.js" "rm" "npm" "-gf"
npm ERR! cwd /tmp/npm.2959/package
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.1
npm ERR! path /usr/local/bin/npm
npm ERR! code EACCES
npm ERR! message EACCES, permission denied '/usr/local/bin/npm'
npm ERR! errno {}
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /tmp/npm.2959/package/npm-debug.log
npm not ok
npm ERR! error installing [email protected]
npm ERR! error rolling back [email protected] Error: EACCES, permission denied '/usr/local/bin/npm'

npm ERR! Error: EACCES, permission denied '/usr/local/bin/npm'
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! 
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "/usr/local/bin/node" "/tmp/npm.2959/package/cli.js" "install" "-gf"
npm ERR! cwd /tmp/npm.2959/package
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.1
npm ERR! path /usr/local/bin/npm
npm ERR! code EACCES
npm ERR! message EACCES, permission denied '/usr/local/bin/npm'
npm ERR! errno {}
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /tmp/npm.2959/package/npm-debug.log
npm not ok
It failed
hrishikesh@hrishikesh-ubuntu:~$ 

我该怎么办?

答案1

解决了。​​StackOverflow 提供帮助。使用以下命令。

curl http://npmjs.org/install.sh | sudo sh

我之前的命令

sudo curl http://npmjs.org/install.sh | sh

正在使用 root 权限获取 url。我应该使用 root 权限执行 sh。

答案2

添加 Chris Lea 的 Repo

使用 Chris Lea 的 Launchpad repo 只需运行以下命令

apt-get install python-software-properties
apt-add-repository ppa:chris-lea/node.js
apt-get update

node.js 安装

apt-get install nodejs

检查 node.js 版本

node -v

输出

v0.10.20

npm 安装

上述命令应该安装 npm。

检查 npm 版本

npm -v

输出

1.4.3

如果由于某种原因,您发现 npm 未安装,您可以尝试运行:

apt-get install npm

答案3

我使用以下方法解决了这个问题:

curl -L http://npmjs.org/install.sh | sudo sh

当我使用 without 时-L,该命令不起作用。

相关内容