没有sudo就无法安装npm软件包

时间:2014-05-03 18:08:20

标签: node.js ubuntu npm

我正在尝试安装node-debugger,无法安装sudo。使用sudo会给我带来一些意想不到的副作用,所以想要安装sudo。以下是错误跟踪

 $  npm install -g node-inspector
npm http GET https://registry.npmjs.org/node-inspector
npm http 304 https://registry.npmjs.org/node-inspector
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/node-inspector'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/node-inspector']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/node-inspector',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/node-inspector',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Linux 3.8.0-35-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "node-inspector"
npm ERR! cwd /home/santhosh/dev/scaleqa/mean_tut/mean_io_original/scaleqaApp
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! path /usr/local/lib/node_modules/node-inspector
npm ERR! fstream_path /usr/local/lib/node_modules/node-inspector
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/node-inspector'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/santhosh/dev/scaleqa/mean_tut/mean_io_original/scaleqaApp/npm-debug.log

npm ERR! not ok code 0

2 个答案:

答案 0 :(得分:0)

使用sudo;这是因为当您全局安装时,NPM会创建从bin文件夹到运行节点的脚本以及包中指定脚本的链接(使node-inspector somescript.js真正运行node /path/to/inspector/node_inspector.js somescript.js

这些bin文件夹受非超级用户保护,因此必须使用sudo来提升访问级别并允许npm写入这些目录。

答案 1 :(得分:0)

系统要求您sudo,因为您正在全局安装npm module,但您使用的是-g,并且它们存储在可由sudo user访问的bin中!

如果您不使用-g,即在本地安装,则不会要求sudo权限!