前言:網速好的使用官方安裝命令Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
我開的科學上網大法,依然十幾KB/S,這誰抗的住。時間久了就出現(xiàn)下面的錯誤。
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
網上有更新git的說法。git config --global http.postBuffer 524288000。親測無效,遇見直接繞行。
現(xiàn)在說說如何解決速度慢導致的安裝失敗的問題。解決思路,使用國內鏡像,比如:中科大,清華大學之類的。我這里使用中科大的鏡像。
一、先獲取官方install文件 命令如下:
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
獲取insatll文件,并且命名為brew_install。
二、利用macOS的快捷搜索command+空格,搜索brew_install。找到后直接打開。
將BREW_REPO = "https://github.com/Homebrew/brew".freeze
改為:BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
我是最新版所以沒有CORE_TAP_REPO,沒有的不需要專門去增加。
如果有CORE_TAP_REPO。
將CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
也改為CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze即可。
三、運行安裝,命令如下。
/usr/bin/ruby brew_install
??注意:代碼會停留在
==> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…
這個位置。不要慌張。??關閉整個終端命令框,重新打開。
輸入以下命令即可:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
四、將brew切換到國內鏡像源
# 步驟一
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 步驟二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
#步驟三
brew update
注意這里需要等待一會,因為要更新資源。
更新完后使用brew update,brew install速度變快很多了,不會卡在那半天沒動靜,替換鏡像完成。
復原方法
# 步驟一
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
# 步驟二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core
#步驟三
brew update
安裝完成后使用以下命令進行診斷,不出錯即為OK。
診斷homebrew
brew doctor
五、brew幾個常用命令
查看homebrew版本
brew -v
查看已安裝的包
brew list
安裝包
brew install packageName
卸載包
brew uninstall packageName
查找包
brew search packageName
查看包信息
brew info packageName
更新homebrew
brew update
診斷homebrew
brew doctor
查看幫助信息
brew -h
參考地址:
https://www.uedbox.com/post/57246/
https://segmentfault.com/a/1190000021360086
生活總會給你第二次機會叫明天