npm install global无法在Mac上运行,说我没有权限?缺少对/ usr / local / lib / node_modules的写入权限

我没有节点模块文件的权限,这不允许我全局安装或更新任何内容。

我知道不建议使用-sudo,因为它稍后可能会导致权限问题。我以为可以更新npm和node来解决此问题,但是我没有执行此操作的权限。

npm ERR! path /usr/local/lib/node_modules
npm ERR! code EaccES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EaccES: permission denied,access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EaccES: permission denied,access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EaccES: permission denied,access \'/usr/local/lib/node_modules\'',npm ERR!   errno: -13,npm ERR!   code: 'EaccES',npm ERR!   syscall: 'access',npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue,please double-check the
npm ERR! permissions of the file and its containing directories,or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
r598933630 回答:npm install global无法在Mac上运行,说我没有权限?缺少对/ usr / local / lib / node_modules的写入权限

我最终使用了这段代码,并且现在可以正常工作了。

sudo chown -R $USER /usr/local/lib/node_modules
本文链接:https://www.f2er.com/3156950.html

大家都在问