我嘗試在 mac 10.6.4 上透過 shell 腳本安裝 npm,但 sudo 似乎不起作用,因為在嘗試存取 /usr/lib 並在該目錄中建立文件時 shell 失敗。怎麼了?
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