npm 不加sudo 执行失败
文章目录
随笔记录一个小问题, npm 安装开源包的时候,你可能碰到这样的情况,无写入权限.
***必须加上 sudo *** 才能执行成功.
无 sudo
➜ /Users/zhangzhi >npm install -g jslint
npm ERR! tar.unpack untar error /Users/zhangzhi/.npm/jslint/0.9.6/package.tgz
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "jslint"
npm ERR! node v4.2.4
npm ERR! npm v2.9.1
npm ERR! path /usr/local/lib/node_modules/jslint
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/jslint'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/jslint']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/jslint',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/jslint',
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:46:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/zhangzhi/yuguo/server-api/npm-debug.log
上面提示在 /usr/local/lib/....... 路径下写入文件报错
解决方法就是给当前用户在此目录下赋予写入权限
➜ /Users/zhangzhi >sudo chown -R $USER /usr/local
Password:
然后我们 去掉 sudo 来执行下:
➜ /Users/zhangzhi >npm install -g jslint
/usr/local/bin/jslint -> /usr/local/lib/node_modules/jslint/bin/jslint.js
jslint@0.9.6 /usr/local/lib/node_modules/jslint
├── exit@0.1.2
├── nopt@3.0.6 (abbrev@1.0.7)
├── readable-stream@1.0.33 (isarray@0.0.1, string_decoder@0.10.31, inherits@2.0.1, core-util-is@1.0.2)
└── glob@4.5.3 (inherits@2.0.1, inflight@1.0.4, once@1.3.3, minimatch@2.0.10)
安装成功!