简体   繁体   中英

Cant install npm packages with out sudo

I am trying to install node-debugger and can't install with out sudo. Using sudo gets me some unexpected sideeffects, so want to install with out sudo. Following is the error trace

 $  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

You have to use sudo ; this is because when you install globally, NPM creates links from your bin folder(s) to scripts that run node and the specified scripts from the packages (making node-inspector somescript.js really run node /path/to/inspector/node_inspector.js somescript.js .

Those bin folders are protected to those who are not super users, therefore sudo must be used to elevate your access level and allow npm to write to those directories.

You are being asked for sudo because you are installing the npm module globally ie you are using -g and they are stored in bin which can be accessed by sudo user !

if you do not use -g ie you install it locally it wont ask for sudo permission!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM