Mac mini(M1,2020)
蒙特雷
布朗尼 v1.17.2
nodejs v16.13.4
我正在根據參考(https://www.youtube.com/watch?v=M576WGiDBdQ&t=25510s)學習可靠性。
Node.JS 安裝沒問題
當我嘗試這個
npm install --global yarn
終端給出錯誤資訊
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/yarn'
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/liwei/.npm/_logs/2022-01-08T12_13_37_765Z-debug.log
(base) liwei@liweideMac-mini-2 com~apple~CloudDocs %
我檢查了檔案的所有者,所有者是root,我應該使用sudo嗎?
(base) liwei@liweideMac-mini-2 com~apple~CloudDocs % ls -l /usr/local/lib/node_modules/npm
total 64
-rw-r--r-- 1 root wheel 9742 10 14 08:49 LICENSE
-rw-r--r-- 1 root wheel 4190 10 19 06:36 README.md
drwxr-xr-x 9 root wheel 288 12 1 19:46 bin
drwxr-xr-x 4 root wheel 128 12 1 19:46 docs
-rw-r--r-- 1 root wheel 145 11 23 14:00 index.js
drwxr-xr-x 77 root wheel 2464 12 1 19:46 lib
drwxr-xr-x 5 root wheel 160 12 1 19:46 man
drwxr-xr-x 188 root wheel 6016 12 1 19:46 node_modules
-rw-r--r-- 1 root wheel 6007 12 1 19:13 package.json
drwxr-xr-x 3 root wheel 96 12 1 19:46 tap-snapshots
(base) liwei@liweideMac-mini-2 com~apple~CloudDocs %
找到這個執行緒(錯誤:EACCES:權限被拒絕,訪問'/usr/local/lib/node_modules'),改變了所有者,stll一個檔案不要改變。
(base) liwei@liweideMac-mini-2 com~apple~CloudDocs % sudo chown -R liwei: /usr/local/lib/node_modules
(base) liwei@liweideMac-mini-2 com~apple~CloudDocs % ls -la /usr/local/lib/node_modules
total 0
drwxr-xr-x 4 liwei wheel 128 1 8 11:51 .
drwxr-xr-x 4 root wheel 128 1 8 11:51 ..
drwxr-xr-x 7 liwei wheel 224 12 1 19:46 corepack
drwxr-xr-x 13 liwei wheel 416 12 1 19:46 npm
這 2 個點是什么?
uj5u.com熱心網友回復:
參考答案在這里(錯誤:EACCES:權限被拒絕,訪問'/usr/local/lib/node_modules')
這對我來說很快。
為了最大限度地減少權限錯誤的可能性,您可以將 npm 配置為使用不同的目錄。在此示例中,您將在主目錄中創建并使用一個隱藏目錄。
備份您的計算機。在命令列的主目錄中,為全域安裝創建一個目錄:
mkdir ~/.npm-global
配置 npm 以使用新的目錄路徑:
npm config set prefix '~/.npm-global'
在您首選的文本編輯器中,打開或創建一個
~/.profile
檔案并添加這一行:
export PATH=~/.npm-global/bin:$PATH
在命令列上,更新您的系統變數:
source ~/.profile
要測驗您的新配置,請在不使用 sudo 的情況下全域安裝包
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/407943.html
標籤:
