1、定義
Homebrew 是一個很方便的包管理器,主要用來管理 mac 操作系統的包,現在也支持 linux 操作系統的包管理。Homebrew 通過 tap 方式定義源,官方默認提供了 brew、homebrew-core 、homebrew-cask 、homebrew-bottles 四個常用的源(倉庫),用戶也可以通過 tap 定義自己的源。
在使用 brew install
安裝軟件的過程中,經常會遇到安裝緩慢、卡死的情況,這大多是由於 Homebrew 的默認安裝源位於國外,國內訪問速度慢造成的,解決這個問題的方法是將安裝源替換爲國內鏡像,常用的國內鏡像包括:阿里巴巴開源鏡像、中科大鏡像、清華鏡像等。
本文的編寫目的是簡單的介紹四個常用的源(源),以及如何更換爲國內鏡像實現快速安裝軟件。
2、brew
說明:Homebrew 源代碼倉庫。
默認地址:https://github.com/Homebrew/brew.git
3、homebrew-core
說明:Homebrew 核心源(倉庫),它是 brew install
的默認安裝源(倉庫)。
默認地址:https://github.com/Homebrew/homebrew-core.git
4、homebrew-cask
說明:homebrew-cask 源(倉庫),提供 macOS 應用和大型二進制文件的安裝。通常我們在 mac 操作系統上安裝圖形用戶界面軟件,系統都會提示“若要安裝,請拖動此圖標…”。homebrew-cask 擴展了Homebrew,爲安裝和管理 Atom 和 Google Chrome 之類的圖形用戶界面應用程序帶來了優雅、簡單和速度。
默認地址:https://github.com/Homebrew/homebrew-cask.git
5、homebrew-bottles
說明:Homebrew 預編譯二進制軟件包。
默認地址:https://bintray.com/homebrew/bottles
6、替換爲國內鏡像源
我的習慣是創建 change_brew.sh 文件,然後在文件中寫入替換源需要的命令。以替換爲中科大鏡像爲例,在 change_brew.sh 文件中寫入如下內容,並執行該腳本,就可以成功切換鏡像源。
#!/bin/bash
# 替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替換homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 應用生效
brew update
# 替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
通過 brew config
命令查看配置信息:
7、還原默認鏡像源
創建 restore_brew.sh 文件,寫入如下內容,執行該文件。
#!/bin/bash
# 替換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://github.com/Homebrew/homebrew-core.git
# 替換homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 應用生效
brew update
執行完 restore_brew.sh 文件後,將 ~/.bash_profile
文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles'
內容刪除,並執行 source ~/.bash_profile
,就恢復了默認的鏡像。
8、常見的國內鏡像
9、參考資料
homebrew github
brew github
homebrew-core github
homebrew-cask github
homebrew-bottles
Homebrew 的關鍵詞定義
文章內容僅代表個人觀點,如有不正之處,歡迎批評指正,謝謝大家。