mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied

mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied_第1张图片
报错日志如下
bogon:documents simple$ blog
-bash: blog: command not found
bogon:documents simple$ rm -rf blog
bogon:documents simple$ hexo init blog
INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Cloning into '/Users/simple/Documents/blog'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 74 (delta 2), reused 4 (delta 2), pack-reused 68
Unpacking objects: 100% (74/74), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/Users/simple/Documents/blog/themes/landscape'...
remote: Enumerating objects: 21, done.        
remote: Counting objects: 100% (21/21), done.        
remote: Compressing objects: 100% (20/20), done.        
remote: Total 917 (delta 4), reused 10 (delta 0), pack-reused 896        
Receiving objects: 100% (917/917), 2.56 MiB | 1.56 MiB/s, done.
Resolving deltas: 100% (484/484), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO  Install dependencies
Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/simple/.npm/_cacache/index-v5/34/f5'

npm WARN deprecated [email protected]: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/simple/.npm/_logs/2019-06-16T19_00_51_668Z-debug.log
WARN  Failed to install dependencies. Please run 'npm install' manually!
bogon:documents simple$ 

今天想弄个hexo的blog 安装时 报错 没有权限操作

mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied_第2张图片
hexo官方文档
mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied_第3张图片
报错后安装的文件缺少

报错缘由

npm安装时没有赋予权限 所有权非普通用户(simple)的权限 ,所以出现局部安装的一个情况 ,这普通用户当然就无权访问了。就会报权限错误。

解决方法

就是把用户目录下的 .npm 文件夹所有权都改成当前用户即可。
比如:当前用户名为 simple

sudo chown -R simple ~/.npm
执行后输入 root 密码,文件所属已改为当前用户了,再执行操作就不会出现了。

mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied_第4张图片
输入root密码

文件所属已改为当前用户 安装正常

注意事项

初学者在用 terminal 操作 npm 的时候,经常会混用 root 和 普通用户。
由于分不清全局安装和局部安装的区别,才会出现乱用root 的问题。

一般来说,全局安装用 root 用户
项目中安装用普通用户,不需要使用 root

感谢:https://blog.csdn.net/kimbing/article/details/88821182

你可能感兴趣的:(mac 中npm 在安装的时候提示 没有权限操作的解决办法 Error: EACCES: permission denied)