npm安装权限被拒绝(macOS)

5 node.js npm npm-install

要安装Bootstrap主题,我想运行npm install。但是,我总是收到一个权限被拒绝的错误。

我已经尝试过nvm,然后切换nvm use 10.9.0运行npm install

我也试过sudo chown -R $(whoami) ~/.npmsudo chown -R $USER /usr/local/lib/node_modules。两者都没有解决,现在我不知道该如何继续。我使用macOS High Sierra。

Marcs-MBP-3:masterclass Marc$ npm install
npm WARN deprecated gulp-uglifyjs@0.6.2: Since gulp-sourcemaps now works, use gulp-uglify instead
npm WARN deprecated babel-preset-es2015@6.24.1:   Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN checkPermissions Missing write access to /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! path /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/Users/Marc/Desktop/Dev/masterclass/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/Users/Marc/Desktop/Dev/masterclass/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).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Marc/.npm/_logs/2018-08-22T12_46_51_786Z-debug.log
Run Code Online (Sandbox Code Playgroud)

Yun*_* ER 71

对于 Mac;

在终端上运行这个>

sudo chown -R $USER /usr/local/lib/node_modules
Run Code Online (Sandbox Code Playgroud)

  • 这也解决了 MacOS High Sierra 上的问题。 (4认同)
  • 可以确认,在 Mac OS Catalina 上遇到了这个问题,这解决了问题 (3认同)
  • 在大苏尔上, sudo chown -R $USER /usr/local/bin (3认同)

小智 34

KIndly 运行以下命令:

  1. 要检查包的位置:

    npm config get prefix

  2. 然后运行这个:

    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

  3. 输入密码并运行安装命令

这对我有用。

  • 我的案例的正确解决方案。 (3认同)
  • 为我解决了问题,谢谢 (3认同)

小智 32

我尝试了这个线程中的所有内容,但在大苏尔上没有运气,但后来我尝试了这个:

sudo npm install -g yarn
Run Code Online (Sandbox Code Playgroud)

它成功了!


小智 12

Check permissions of your project root with ls -l /Users/Marc/Desktop/Dev/masterclass/. If the owner is not $USER, delete your node_modules directory, try changing the owner of that directory instead and run npm install again.

cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass    
npm install
Run Code Online (Sandbox Code Playgroud)


Sig*_*gex 7

对我来说,

npm cache clean --force
rm -rf node_modules
npm install
Run Code Online (Sandbox Code Playgroud)

我尝试手动删除但没有帮助


Jap*_*pes 5

对于运行 Big Sur 或 Monterey 的 Mac:

sudo chown -R $USER /usr/local/bin