我尝试在 Mac 10.6.4 上通过 shell 脚本安装 npm,但 sudo 似乎不起作用,因为 shell 在尝试访问 /usr/lib 并在该目录中创建文档时失败。哪里出了问题?
fred:echowaves fred$ sudo curl http://npmjs.org/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3927 100 3927 0 0 3702 0 0:00:01 0:00:01 --:--:-- 6975
fetching: http://registry.npmjs.org/npm/-/npm-1.0.22.tgz
0.4.10
1.0.22
prefix=/usr
This script will find and eliminate any shims, symbolic
links, and other cruft that was installed by npm 0.x.
Is this OK? enter 'yes' or 'no'
es
Is this OK? enter 'yes' or 'no'
yes
All clean!
! [ -d .git ] || git submodule update --init --recursive
node cli.js cache clean
node cli.js rm npm -g -f --loglevel error
node cli.js install -g -f
npm ERR! Could not create /usr/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCES, Permission denied '/usr/lib/node_modules/___npm.npm'
npm ERR! Error: EACCES, Permission denied '/usr/lib/node_modules/___npm.npm'
npm ERR!
npm ERR! Please use 'sudo' or log in as root to run this command.
npm ERR!
npm ERR! sudo npm "install" "-g" "-f"
npm ERR!
npm ERR! or set the 'unsafe-perm' config var to true.
npm ERR!
npm ERR! npm config set unsafe-perm true
npm ERR!
npm ERR! System Darwin 11.0.0
npm ERR! command "node" "/private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package
npm ERR! node -v v0.4.10
npm ERR! npm -v 1.0.22
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package/npm-debug.log
npm not ok
make: *** [install] Error 13
npm ERR! Could not create /usr/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCES, Permission denied '/usr/lib/node_modules/___npm.npm'
npm ERR! Error: EACCES, Permission denied '/usr/lib/node_modules/___npm.npm'
npm ERR!
npm ERR! Please use 'sudo' or log in as root to run this command.
npm ERR!
npm ERR! sudo npm "install" "-gf"
npm ERR!
npm ERR! or set the 'unsafe-perm' config var to true.
npm ERR!
npm ERR! npm config set unsafe-perm true
npm ERR!
npm ERR! System Darwin 11.0.0
npm ERR! command "/usr/bin/node" "/private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package
npm ERR! node -v v0.4.10
npm ERR! npm -v 1.0.22
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/lf/7q2cr83j2nvdvp266pg6p0180000gn/T/npm.64068/package/npm-debug.log
npm not ok
It failed
fred:echowaves fred$
答案1
看起来您正在sudo curl http://npmjs.org/install.sh
以 root 身份运行命令的第一部分 ( ),然后使用常规帐户权限将其传输到 sh。尝试将其拆分为两个命令:
sudo curl -O http://npmjs.org/install.sh
sudo ./install.sh
答案2
Sudo 仅影响 curl。运行命令之前,您应该切换到 root 权限。输入:
$ sudo su
root$ curl http://npmjs.org/install.sh | sh
root$ exit