1. brew update error
(i) 問題出現及現象描述
昨天換了台電腦,有些軟體需要重新安裝或更新一下,遇到了下面的問題
cv@xys-MacBook-Pro ~ % brew update
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
fatal: Unable to create \'/usr/local/Homebrew/.git/index.lock\': Permission denied
fatal: Unable to create \'/usr/local/Homebrew/.git/index.lock\': Permission denied
error: could not lock config file .git/config: Permission denied
Already up-to-date.
(ii) 解決方案
在***上找到了一個類似的問題,用高贊的回答解決了這個問題。
直接通過改變 /usr/local 的所屬使用者進而解決權限問題。
不同的版本使用的指令略有不同,如果是 macOS High Sierra 或更高版本的系統的使用者,使用下面的指令可以修改所屬權,
~$ sudo chown -R $(whoami) $(brew --prefix)/*
如果是 macOS Sierra 或更低版本的系統的使用者,使用下面的指令
~$ sudo chown -R $(whoami) /usr/local
檢視本機系統版本資訊,可以通過單擊左上角蘋果 Logo ==> 關于本機,就能看到系統版本号及其名稱。版本号之間的高低可以通過WikiPedia上面記載的版本與名稱對應清單來查詢。
Public Beta: "Kodiak", Released on September 13, 2000
Version 10.0: "Cheetah", Released on March 24, 2001
Version 10.1: "Puma", Released on September 25, 2001
Version 10.2: "Jaguar", Released on August 23, 2002
Version 10.3: "Panther", Released on October 24, 2003
Version 10.4: "Tiger", Released on April 29, 2005
Version 10.5: "Leopard", Released on October 26, 2007
Version 10.6: "Snow Leopard", Released on August 28, 2009
Version 10.7: "Lion", Released on July 20, 2011
Version 10.8: "Mountain Lion", Released on July 25, 2012
Version 10.9: "Mavericks", Released on October 22, 2013
Version 10.10: "Yosemite", Released on October 16, 2014
Version 10.11: "El Capitan", Released on June 8, 2015
Version 10.12: "Sierra", Released on June 13, 2016
Version 10.13: "High Sierra", Released on June 5, 2017
Version 10.14: "Mojave", Released on June 4, 2018
Version 10.15: "Catalina", Released on June 3, 2019
Version 11: "Big Sur", Released on June 22, 2020
2. brew update "Fetching homebrew-cask failed!"
(i) 問題描述
盡管權限問題用上述方法解決了,但後續執行時又遇到了一點問題,這次是主要是Homebrew的其中兩個組成部分
homebrew-cask
和
homebrew-core
引起的,出現了如下所示的 "Fetching failed" 錯誤。
cv@xys-MBP ~ % brew update
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
Updated 2 taps (homebrew/cask and caskroom/cask).
(ii) 解決方案
嘗試了一些方法都沒解決,最後選擇重新安裝 Homebrew,畢竟沒有什麼問題是重裝不能解決的,如過有,就連系統一起重裝...話說回來,重裝之後确實沒有問題了(\汗)。
首先自然是解除安裝已有的安裝版本,指令是
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
,結果如下。
cv@xys-MBP ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in
Bash. Please migrate to the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
cv@xys-MBP ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)
接着當然是安裝新版本,指令是
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
,結果如下,中間有一次需要根據自己的需求選擇源并輸入 root 密碼。
cv@xys-MBP ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
開始執行Brew自動安裝程式
[[email protected]]
[\'2021-05-20 17:53:17\'][\'11.3\']
https://zhuanlan.zhihu.com/p/111014448
請選擇一個下載下傳鏡像,例如中科大,輸入1回車。
源有時候不穩定,如果git克隆報錯重新運作腳本選擇源。cask非必須,有部分人需要。
1、中科大下載下傳源 2、清華大學下載下傳源 3、北京外國語大學下載下傳源 4、騰訊下載下傳源(不推薦) 5、阿裡巴巴下載下傳源(不推薦 缺少cask源)
請輸入序号:
我選擇了中科大下載下傳源,輸入 1 回車即可。
你選擇了中國科學技術大學下載下傳源
!!!此腳本将要删除之前的brew(包括它下載下傳的軟體),請自行備份。
->是否現在開始執行腳本(N/Y)
是否執行,選擇是,輸入 Y 回車繼續。接着輸入密碼後正常情況下就能一直運作到最後了,如果中間斷了根據提示進行相應的操作即可。
--> 腳本開始執行
Mac os設定開機密碼方法:
(設定開機密碼:在左上角蘋果圖示->系統偏好設定->使用者與群組->更改密碼)
(如果提示This incident will be reported. 在使用者與群組中檢視是否管理者)
==> 通過指令删除之前的brew、建立一個新的Homebrew檔案夾
請輸入開機密碼,輸入過程不顯示,輸入完後回車
開始執行
---備份要删除的/usr/local/Homebrew到系統桌面....
---/usr/local/Homebrew 備份完成
-> 建立檔案夾 /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
此步驟成功
運作代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
git version 2.20.1
下載下傳速度覺得慢可以ctrl+c或control+c重新運作腳本選擇下載下傳源
==> 克隆Homebrew基本檔案
未發現Git代理(屬于正常狀态)
Cloning into \'/usr/local/Homebrew\'...
remote: Enumerating objects: 191263, done.
remote: Total 191263 (delta 0), reused 0 (delta 0) | 10.55 MiB/s
Receiving objects: 100% (191263/191263), 48.84 MiB | 10.64 MiB/s, done.
Resolving deltas: 100% (142769/142769), done.
此步驟成功
--建立Brew所需要的目錄
運作代碼 ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin/brew
運作代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin/brew
運作代碼 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/sbin /usr/local/Caskroom
運作代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin /usr/local/Caskroom
運作代碼 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/sbin /usr/local/Caskroom
運作代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/sbin /usr/local/Caskroom
運作代碼 ==> /usr/bin/sudo /usr/sbin/chown -R cv:admin /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /bin/mkdir -p /Users/cv/Library/Caches/Homebrew
運作代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/cv/Library/Caches/Homebrew
運作代碼 ==> /usr/bin/sudo /usr/sbin/chown -R cv /Users/cv/Library/Caches/Homebrew
--依賴目錄腳本運作完成
==> 建立brew的替身
==> 克隆Homebrew Core
此處如果顯示Password表示需要再次輸入開機密碼,輸入完後回車
Cloning into \'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core\'...
remote: Enumerating objects: 960954, done.
remote: Total 960954 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (960954/960954), 380.33 MiB | 10.66 MiB/s, done.
Resolving deltas: 100% (660866/660866), done.
Checking out files: 100% (5914/5914), done.
此步驟成功
==> 克隆Homebrew Cask 圖形化軟體
此處如果顯示Password表示需要再次輸入開機密碼,輸入完後回車
Cloning into \'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask\'...
remote: Enumerating objects: 624249, done.
remote: Total 624249 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (624249/624249), 260.95 MiB | 9.69 MiB/s, done.
Resolving deltas: 100% (445746/445746), done.
此步驟成功
==> 克隆Homebrew services 管理服務的啟停
Cloning into \'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services\'...
remote: Enumerating objects: 1141, done.
remote: Counting objects: 100% (1141/1141), done.
remote: Compressing objects: 100% (495/495), done.
remote: Total 1141 (delta 484), reused 1141 (delta 484), pack-reused 0
Receiving objects: 100% (1141/1141), 331.50 KiB | 330.00 KiB/s, done.
Resolving deltas: 100% (484/484), done.
此步驟成功
==> 配置國内鏡像源HOMEBREW BOTTLE
sed: /Users/cv/.zprofile: No such file or directory
環境變量寫入->/Users/cv/.zprofile
此步驟成功
運作代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/Homebrew
運作代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
==> 安裝完成,brew版本
Homebrew 3.1.8-50-g76c4767-dirty
Homebrew/homebrew-core (git revision 832bb8b966; last commit 2021-05-20)
Homebrew/homebrew-cask (git revision f397055044; last commit 2021-05-20)
Brew前期配置成功
電腦系統版本:11.3
All user-space services OK, nothing cleaned...
==> brew update-reset
==> Fetching /usr/local/Homebrew...
==> Resetting /usr/local/Homebrew...
Branch \'master\' set up to track remote branch \'master\' from \'origin\'.
Reset branch \'master\'
Your branch is up to date with \'origin/master\'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking out files: 100% (3977/3977), done.
Branch \'master\' set up to track remote branch \'master\' from \'origin\'.
Reset branch \'master\'
Your branch is up to date with \'origin/master\'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Checking out files: 100% (5659/5659), done.
Branch \'master\' set up to track remote branch \'master\' from \'origin\'.
Reset branch \'master\'
Your branch is up to date with \'origin/master\'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
Branch \'master\' set up to track remote branch \'master\' from \'origin\'.
Reset branch \'master\'
Your branch is up to date with \'origin/master\'.
Brew自動安裝程式運作完成
國内位址已經配置完成
桌面的Old_Homebrew檔案夾,大緻看看沒有你需要的可以删除。
初步介紹幾個brew指令
本地軟體庫清單:brew ls
查找軟體:brew search google(其中google替換為要查找的關鍵字)
檢視brew版本:brew -v 更新brew版本:brew update
安裝cask軟體:brew install --cask firefox 把firefox換成你要安裝的
歡迎右鍵點選下方位址-打開URL 來給點個贊
https://zhuanlan.zhihu.com/p/111014448
重新開機終端 或者 運作 source /Users/cv/.zprofile 否則可能無法使用
安裝完成後按照提示運作 source 指令
cv@xys-MBP ~ % source ~/.zprofile
至此重裝過程結束,開始正常使用 Homebrew。
(全文完)
參考資料
[1] brew update fails with “Permission denied” error (https://***.com/questions/50267510/brew-update-fails-with-permission-denied-error/50268978)
[2] macOS version history (https://en.wikipedia.org/wiki/MacOS_version_history)
[3] mac下Homebrew安裝Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed報錯解決方法 (http://www.cxyzjd.com/article/Jiangzhiqi4551/116174524)
[4] Mac 下 brew 切換為國内源 (https://cloud.tencent.com/developer/article/1614039)
附國内一些開源鏡像網址
-
中國科學技術大學開源軟體鏡像(目前***高校通路量最大、收錄最全的開源軟體鏡像,由中國科學技術大學網絡資訊中心提供支援)
https://mirrors.ustc.edu.cn/
-
清華大學開源軟體鏡像(由清華大學資訊化技術中心支援創辦,由清華大學 TUNA 協會運作維護)
https://mirrors.tuna.tsinghua.edu.cn/
-
北京外國語大學開源軟體鏡像(由北外資訊技術中心支援創辦,由清華大學 TUNA 協會運作維護)
https://mirrors.bfsu.edu.cn/
-
騰訊雲軟體源
https://mirrors.cloud.tencent.com/
-
阿裡雲鏡像源(由阿裡巴巴技術保障部基礎系統組提供支援)
https://mirrors.aliyun.com/
-
網易開源鏡像
https://mirrors.163.com/
本文作者 :phillee
發表日期 :2021年5月20日
本文連結 :https://www.cnblogs.com/phillee/p/14788909.html
版權聲明 :***轉載-非商用-非衍生-保持署名(創意共享3.0許可協定/CC BY-NC-SA 3.0)。轉載請注明出處!
限于本人水準,如果文章和代碼有表述不當之處,還請不吝賜教。