在OSX上安装npm的权限问题

时间:2011-12-05 03:36:12

标签: node.js npm

我在安装节点包管理器“npm”时遇到问题。

website上,它会提示您按如下方式进行1行安装...

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

这会吐出以下安装错误...

$ curl http://npmjs.org/install.sh | sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7184  100  7184    0     0  27012      0 --:--:-- --:--:-- --:--:-- 39256
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz
0.4.11
1.0.106
cleanup prefix=/usr

All clean!
npm ERR! Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "/usr/bin/node" "/private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package/cli.js" "rm" "npm" "-gf"
npm ERR! cwd /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package
npm ERR! node -v v0.4.11
npm ERR! npm -v 1.0.106
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package/npm-debug.log
npm not ok
npm ERR! error installing npm@1.0.106 Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! error rolling back npm@1.0.106 Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "/usr/bin/node" "/private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package
npm ERR! node -v v0.4.11
npm ERR! npm -v 1.0.106
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.72890/package/npm-debug.log
npm not ok

googling around之后看起来这是一个常见的问题,修复它的方法就是运行与sudo前面相同的命令。

奇怪的是,这在我的案例中似乎不起作用。如果我运行相同的命令sudo'd会发生这种情况。

$ sudo curl http://npmjs.org/install.sh | sh
Password:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7184  100  7184    0     0   9974      0 --:--:-- --:--:-- --:--:-- 40359
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz
0.4.11
1.0.106
cleanup prefix=/usr

All clean!
npm ERR! Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "/usr/bin/node" "/private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package/cli.js" "rm" "npm" "-gf"
npm ERR! cwd /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package
npm ERR! node -v v0.4.11
npm ERR! npm -v 1.0.106
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package/npm-debug.log
npm not ok
npm ERR! error installing npm@1.0.106 Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! error rolling back npm@1.0.106 Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Error: EACCES, Permission denied '/usr/bin/npm'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "/usr/bin/node" "/private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package
npm ERR! node -v v0.4.11
npm ERR! npm -v 1.0.106
npm ERR! path /usr/bin/npm
npm ERR! code EACCES
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/mn/8q6c34bj67xbxk08dwlsb_y40000gn/T/npm.81519/package/npm-debug.log
npm not ok
It failed

我在这里画一个空白。有什么想法吗?

2 个答案:

答案 0 :(得分:18)

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

sh需要权限,而不是curl

答案 1 :(得分:1)

这对我有用

git clone http://github.com/isaacs/npm.git
cd npm
sudo make install