我已经安装了Node和NPM。
$ node -v
v0.10.25
$ npm -v
1.3.24作为一个普通用户,如果我试图安装一个全局包,我会得到一个权限错误:
$ npm -g install grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/bin/grunt'
npm ERR! error rolling back grunt-cli@0.1.13 { [Error: EACCES, unlink '/usr/local/bin/grunt'] errno: 3, code: 'EACCES', path: '/usr/local/bin/grunt' }
npm ERR! Error: EACCES, unlink '/usr/local/bin/grunt'
npm ERR! { [Error: EACCES, unlink '/usr/local/bin/grunt'] errno: 3, code: 'EACCES', path: '/usr/local/bin/grunt' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.很公平,让我用sudo
$ sudo npm -g install grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)看起来不错,但现在如果我尝试使用我的新安装的软件包,我不能:
$ grunt
fs.js:695
return binding.readlink(pathModule._makeLong(path));
^
Error: EACCES, permission denied '/usr/local/bin/grunt'
at Object.fs.readlinkSync (fs.js:695:18)
at Object.realpathSync (fs.js:1283:25)
at tryFile (module.js:142:15)
at Function.Module._findPath (module.js:181:18)
at Function.Module._resolveFilename (module.js:336:25)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3令人沮丧。但是,如果我卸载了sudo npm -g uninstall grunt-cli,然后完全切换到root,然后再试一次,它可以工作:
$ sudo su -
root# npm -g install grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)
^D
$ grunt
grunt-cli: The grunt command line interface. (v0.1.13)这发生在所有的全球包(咕噜,监督等),是令人难以置信的沮丧。为什么sudo会失败,但是su会工作呢?我能做些什么来修复我的环境?
发布于 2014-01-24 22:25:06
据猜测,它可能是umask --您可能有077,而root的缺省值类似于022。因此,对于sudo,创建的文件不是世界可读的,但是使用su它们是可读的。
当您使用sudo安装时,文件/usr/local/bin/grunt的权限/所有权是什么?
https://stackoverflow.com/questions/21343453
复制相似问题