Homebrew替換國內(nèi)源

Homebrew是什么

Homebrew 是一個MacOS 上的包管理器,你可以用它來安裝管理軟件,功能非常強大,基本上只要是MacOS上能安裝的軟件,你通過Homebrew 都能夠安裝。類似于Linux上的yum,或者nodejs的npm。

有人可能會說,我要安裝軟件,直接到App Store上下載不就行了嗎?但是并不是所有,或者說,大部分軟件你在App Store上找不到的,特別是對于開發(fā)人員所需的軟件更是,基本在App Store找不到。

什么是Homebrew的源

其實就是一個giturl,對應(yīng)的是git倉庫。
每次通過Homebrew安裝軟件,Homebrew會根據(jù)源,會比對、下載(或者merge)源倉庫到本地,然后根據(jù)要下載的軟件找到對應(yīng)的xxx.rb文件,然后再根據(jù)rb文件中內(nèi)容一步步的校驗、下載、安裝軟件。

為什么要替換Homebrew的源

因為慢慢慢慢啊!Homebrew原始源是以下:

# homebrew源
https://github.com/Homebrew/brew.git
# homebrew-core源
https://github.com/Homebrew/homebrew-core.git
# homebrew-cask源
https://github.com/Homebrew/homebrew-cask.git

大家可以看到,都是github,國內(nèi)訪問這些源時,經(jīng)常性的慢出翔,所以必須替換為國內(nèi)源,加快速度。

開始替換(4個地方)

國內(nèi)源有幾個不錯的:

以下是替換清華的源

# 替換brew.git源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替換 homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替換 homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

其實替換這三個源就可以了,另外就是homebrew-bottles,這個配置個HOMEBREW_BOTTLE_DOMAIN環(huán)境變量,不過我發(fā)現(xiàn)我不配置也沒啥問題:

# 使用bash的話
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

# 使用zsh的話
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

以下是替換為中科大的源

# brew.git源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 配置homebrew-bottles
## bash用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
## zsh用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

復(fù)核配置是否成功

設(shè)置完之后,可以執(zhí)行以下命令,查看配置是否已經(jīng)替換成功

# 查看brew.git源
git -C "$(brew --repo)" config --get remote.origin.url
# 查看homebrew-core.git源
git -C "$(brew --repo homebrew/core)" config --get remote.origin.url
# 查看homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" config --get remote.origin.url

最后執(zhí)行brew update來嘗試一下看是否速度更快。

重置為官方源

如果你想重置為官方的源,可以如下操作:

# brew.git源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core
# homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask

另外記住刪除 HOMEBREW_BOTTLE_DOMAIN 環(huán)境變量

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Mac下使用國內(nèi)鏡像安裝Homebrew First MBP上的brew很老了,就想把brew更新一下,順便安裝一...
    采姑娘的小魔鈷閱讀 65,872評論 20 65
  • Homebrew是一款自由及開放源代碼的軟件包管理系統(tǒng),用以簡化macOS系統(tǒng)上的軟件安裝過程。對于Appstor...
    巖杉Shawn閱讀 14,570評論 2 7
  • Homebrew是一款自由而且開放源碼的軟件包管理系統(tǒng),用以簡化Mac OS系統(tǒng)的軟件安裝過程。 Homebre...
    JZ_Gordon閱讀 1,032評論 0 2
  • homebrew是osx下的一個包管理工具,可以很方便的管理各類包。官方給出的定義是 macOS缺失的軟件包管理器...
    ouisun閱讀 17,602評論 1 63
  • 久違的晴天,家長會。 家長大會開好到教室時,離放學(xué)已經(jīng)沒多少時間了。班主任說已經(jīng)安排了三個家長分享經(jīng)驗。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,870評論 16 22

友情鏈接更多精彩內(nèi)容