在Mac系统中,使用npm全局安装有时会报错,例如:
npm install -g gulp
报以下错误
checkPermissions Missing write access to /usr/local/lib/node_modules/gulp
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules/gulp
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/gulp'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/gulp'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/gulp'
npm ERR! }
原因是目录权限问题,做如下修改
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
再次执行命令就好了。