npm 在安裝的時候提示 沒有權限操做的解決辦法 Error: EACCES: permission denied

npm 在安裝的時候提示 沒有權限操做的解決辦法 Error: EACCES: permission denied

在安裝插件的時候出現這樣的錯誤,權限不夠,是由於以前用 root 用戶進行了局部安裝npm包的操做,留下所屬權爲 root 的文件,致使普通用戶沒法訪問 root的文件內容。npm

報錯日誌以下:

clipboard.png

npm ERR! path /Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c'
npm ERR!  { [Error: EACCES: permission denied, open '/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, open '/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'open',
npm ERR!      path:
npm ERR!       '/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c' },
npm ERR!   isOperational: true,
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, open \'/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path:
npm ERR!    '/Users/Kyle/.npm/_cacache/index-v5/d8/1f/98ab242d0cbad080828ef3e3f4b864c25e506a719121c293fec810b14b3c',
npm ERR!   parent: 'findup-sync' }
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/Kyle/.npm/_logs/2019-03-26T07_00_54_812Z-debug.log

錯誤緣由:

找到報錯的文件,會看到它的全部者是 root
以前用 root 進行了局部的安裝操做,致使這個文件的全部者是 root ,還包括 .npm 文件夾下部分文件夾的全部權,也是 root,普通用戶固然就無權訪問了。就會報權限錯誤。bash

clipboard.png

解決辦法

就是把用戶目錄下的 .npm 文件夾全部權都改爲當前用戶便可。
好比:當前用戶名爲 Kylethis

sudo chown -R Kyle ~/.npm

執行後輸入 root 密碼,文件所屬已改成當前用戶了,再執行操做就不會出現了。spa

clipboard.png

clipboard.png

注意事項

初學者在用 terminal 操做 npm 的時候,常常會混用 root 和 普通用戶。
因爲分不清全局安裝和局部安裝的區別,纔會出現亂用root 的問題。插件

通常來講,全局安裝用 root 用戶
項目中安裝用普通用戶,不須要使用 rootdebug

相關文章
相關標籤/搜索