C/C++教程

NPM 安装报 Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/xxxxxx‘ 解决

本文主要是介绍NPM 安装报 Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/xxxxxx‘ 解决,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

今天使用 npm i docsify-cli -g 安装 node 脚手架工具时,出现以下错误:

andrew@Andrews-MacBook-Pro CSNotes % npm i docsify-cli -g
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/docsify-cli
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/docsify-cli'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/docsify-cli'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/docsify-cli'
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/andrew/.npm/_logs/2022-03-12T07_59_19_036Z-debug-0.log

看到 Error: EACCES: permission denied 这句话时,该问题很明显是用户权限不足了。

2 解决方案
解决该权限问题核心思想是提权,但有两种思路:

对文件目录提权
sudo chown -R $USER /usr/local/lib/node_modules
1
对执行用户提权
sudo npm i docsify-cli -g

最终我们顺利安装成功:
————————————————
原文链接:https://blog.csdn.net/adminpd/article/details/123445374

这篇关于NPM 安装报 Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/xxxxxx‘ 解决的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!