mac 中npm 在安裝的時(shí)候提示 沒(méi)有權(quán)限操作的解決辦法 Error: EACCES: permission denied

報(bào)錯(cuò)日志如下
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 core-js@1.2.7: 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!     <https://npm.community>

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$ 

今天想弄個(gè)hexo的blog 安裝時(shí) 報(bào)錯(cuò) 沒(méi)有權(quán)限操作

hexo官方文檔
報(bào)錯(cuò)后安裝的文件缺少

報(bào)錯(cuò)緣由

npm安裝時(shí)沒(méi)有賦予權(quán)限 所有權(quán)非普通用戶(hù)(simple)的權(quán)限 ,所以出現(xiàn)局部安裝的一個(gè)情況 ,這普通用戶(hù)當(dāng)然就無(wú)權(quán)訪(fǎng)問(wèn)了。就會(huì)報(bào)權(quán)限錯(cuò)誤。

解決方法

就是把用戶(hù)目錄下的 .npm 文件夾所有權(quán)都改成當(dāng)前用戶(hù)即可。
比如:當(dāng)前用戶(hù)名為 simple

sudo chown -R simple ~/.npm
執(zhí)行后輸入 root 密碼,文件所屬已改為當(dāng)前用戶(hù)了,再執(zhí)行操作就不會(huì)出現(xiàn)了。

輸入root密碼

文件所屬已改為當(dāng)前用戶(hù) 安裝正常

注意事項(xiàng)

初學(xué)者在用 terminal 操作 npm 的時(shí)候,經(jīng)常會(huì)混用 root 和 普通用戶(hù)。
由于分不清全局安裝和局部安裝的區(qū)別,才會(huì)出現(xiàn)亂用root 的問(wèn)題。

一般來(lái)說(shuō),全局安裝用 root 用戶(hù)
項(xiàng)目中安裝用普通用戶(hù),不需要使用 root

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容