懶人操作順序:S_01>>>S_02>>>S_03
首先這是homebrew的官網
https://brew.sh/index_zh-cn
安裝方法是在終端中輸入 下面這行代碼 // 但是官網很慢 可以考慮看S_01開始的更換鏡像的步驟
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
需要說明的是最好提前在終端中將curl的postBuffer的默認值提高
不然,可能會報如下的錯誤信息 ( 指給的空間不夠 )
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
對此的解決方法是
S_01
拓展空間
在終端中輸入
git config --global http.postBuffer 1048576000 # 這里的數字是字節數 # 這里給的是 1000MB 也就是1000 * 1024 * 1024 # 可以根據自己的需求更改數值 # 修改完畢后 可以通過以下命令查看postBuffer git config --list
還可能出現以下錯誤 即提示網速不夠 請求被停止了
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
可以通過以下方法解決:
S_02
更換鏡像
更換下載源到國內的阿里巴巴的源或者清華源:
step1:在終端輸入 ( 這一步會在終端執行的文件夾下面獲取homebrew的install文件腳本)
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
step2:在終端輸入 ( 得到當前的執行目錄,一般來說會在/User/你的用戶名 )
pwd
strp3:復制step2得到的地址 ( 比如得到的是‘/User/你的用戶名’ ),
然后 在finder-前往文件夾-輸入該地址 點擊前往
( 不會前往文件夾的話,看這里:*https://www.cnblogs.com/PowerTips/p/11165161.html* )
就能看到該文件 ( 如下圖 )
step4:右擊該文件,用文本編輯打開,然后把如下幾行改成step5中的代碼。
step5:以下代碼會將homebrew的安裝以及之后的下載源改到Alibaba的源 或者清華源
# 更換到阿里的鏡像
HOMEBREW_PREFIX = "/usr/local".freeze HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze HOMEBREW_CORE_TAP = "https://mirrors.aliyun.com/homebrew/homebrew-core.git".freeze HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze BREW_REPO = "https://mirrors.aliyun.com/homebrew/brew.git".freeze
#=======================================================
# 更換到清華源
HOMEBREW_PREFIX = "/usr/local".freeze HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze HOMEBREW_CORE_TAP = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
step6:如果你在step3找到該腳本文件 ( brew_install ) 后,沒有把這個腳本文件移到別的文件夾下面
那么繼續在終端輸入
ruby brew_install
如果你移到別的文件夾下面了,執行之前在前面加上當前文件夾的目錄
S_03
如果你卡在 Updating Homebrew,嘗試step7
step7(補充):現在應該就能安裝了,現在可以選擇替換homebrew-bottles訪問地址到阿里巴巴的homebrew-bottles(之前大概也能選擇,現在選也沒關系)
第一步:查看MacOS現在使用的shell
echo $SHELL
# 如果你的輸出結果是 /bin/zsh,參考 zsh 終端操作方式
# 如果你的輸出結果是 /bin/bash,參考 bash 終端操作方式
第一步(補充):Mac系統默認使用dash作為終端,可以使用命令修改默認使用zsh:
chsh -s /bin/zsh
為什么要替換?:具體可以查看https://www.xshell.net/shell/bash_zsh.html
當然,替換回來也很簡單
chsh -s /bin/bash
需要注意的是,替換過后,要把終端退出再打開才生效
第二步:如果你是 zsh 終端
# 替換成阿里巴巴的 homebrew-bottles 訪問地址: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc source ~/.zshrc #======================================================= # 還原為官方提供的 homebrew-bottles 訪問地址 vi ~/.zshrc # 然后,刪除 HOMEBREW_BOTTLE_DOMAIN 這一行配置 source ~/.zshrc
如果你是bash終端
# 替換成阿里巴巴的 homebrew-bottles 訪問地址: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile #======================================================= # 還原為官方提供的 homebrew-bottles 訪問地址 vi ~/.bash_profile # 然后,刪除 HOMEBREW_BOTTLE_DOMAIN 這一行配置 source ~/.bash_profile
S_04
題外話:
如果你之前已經嘗試過安裝,並沒有按照S_01>>>S_02>>>S_03的步驟來
執行了step1也得不到brew_install腳本文件
那么,建議你在執行了step7的基礎上執行下面兩部分
第一部分(執行👇分割線以上的阿里巴巴的源就可以了)
# 替換成阿里巴巴的 brew.git 倉庫地址: cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git #======================================================= # 還原為官方提供的 brew.git 倉庫地址 cd "$(brew --repo)" git remote set-url origin https://github.com/Homebrew/brew.git
第二部分(執行👇分割線以上的阿里巴巴的源就可以了)
# 替換成阿里巴巴的 homebrew-core.git 倉庫地址: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git #======================================================= # 還原為官方提供的 homebrew-core.git 倉庫地址 cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://github.com/Homebrew/homebrew-core.git
最后執行
/usr/local/bin/ruby ~/brew_install
安裝后的地址
/usr/local/Homebrew/
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
https://learnku.com/articles/18908