訪問我的Github(地址:https://guobo507.github.io)查看最新文章列表。
文章目錄
許多小夥伴可能都有同感,當我們直接使用官方提供的ruby腳本在MacOS上安裝brew時大概率會發現無法訪問,即便可以訪問也會慢如蝸牛。
針對這種情況呢,國內很多開源景象站都提供了brew工具的安裝源。這裏,我們需要先想辦法使用瀏覽器訪問如下兩個地址,打開這兩個網頁(純文本格式的網頁),分別保存爲對應的文件。如下所示:
- 安裝腳本地址:https://raw.githubusercontent.com/Homebrew/install/master/install,保存爲
brew_install.rb
- 卸載腳本地址:https://raw.githubusercontent.com/Homebrew/install/master/uninstall,保存爲
brew_uninstall.rb
然後使用你習慣的文本編輯器,更改brew_install.rb
腳本中的對應的資源鏈接地址。比如,你想將其替換成清華大學的鏡像,可以修改如下兩句:
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
修改爲如下所示:
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze # 修改
CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze # 新增
當然,如果你發現有更好的、更適合你的鏡像源,也可以換成別的鏡像地址。
然後,你就可以放心執行如下操作安裝brew了:
ruby /PATH/brew_install.rb
當安裝完成brew軟件後,我們可以試着安裝一個工具軟件來測試一下。例如,我這裏嘗試安裝hugo(一個開源的博客站點工具)工具:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
brew update
brew install hugo
which hugo
如果你想長期替換執行brew install
命令時所使用的軟件源倉庫的地址,可以參考下面的方法設置你的Shell環境變量:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile