npm, global install failing, getting Error: EACCES: permission denied

npm, global install failing, getting Error: EACCES: permission denied

所以我以我的 MacBook 的管理员身份登录并想 运行 我的 Django 项目中的 npm 命令。但是,由于缺少权限,它拒绝了。

(venv) jonas@Air-von-Jonas salaryx % npm install -g sass
npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/sass/sass.js
npm ERR! dest /usr/local/bin/sass
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/sass/sass.js' -> '/usr/local/bin/sass'
npm ERR!  [Error: EACCES: permission denied, symlink '../lib/node_modules/sass/sass.js' -> '/usr/local/bin/sass'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/sass/sass.js',
npm ERR!   dest: '/usr/local/bin/sass'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jonas/.npm/_logs/2022-03-24T06_04_35_362Z-debug.log
(venv) jonas@Air-von-Jonas salaryx % 

我似乎也无法更改文件夹的权限,我可以解锁右下角的锁,但是一旦我尝试更改“wheel”的权限,例如它也拒绝。

全局安装 npm 包的一种简单方法是使用 sudo 命令,如下所示:

sudo npm install -g sass