Mac下使用國(guó)內(nèi)鏡像安裝Homebrew

Mac下使用國(guó)內(nèi)鏡像安裝Homebrew

First

MBP上的brew很老了,就想把brew更新一下,順便安裝一下NodeJs。無奈更新的過程一直卡在網(wǎng)絡(luò)下載,毫不動(dòng)彈。想想,應(yīng)該是Repo訪問不到的原因,于是重裝brew。

根據(jù)官網(wǎng)上的方法,在終端輸入:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

結(jié)果還是被卡在下載階段,怎么辦呢?于是上網(wǎng)搜索到了“Homebrew 的安裝方法(官方的方法老是安裝失敗) 第三方”這篇文章。

依文中所述,進(jìn)行安裝。由于官方棄用了舊的homebrew倉(cāng)庫(kù),將homebrew程序與軟件包拆分成了兩個(gè)倉(cāng)庫(kù)。與文中描述不符,也未能成功安裝。于是稍作修改,記錄于此。

國(guó)內(nèi)的鏡像

新增brew.git與homebrew-core.git鏡像

由于官方棄用了舊的homebrew倉(cāng)庫(kù),將homebrew程序與軟件包拆分成了兩個(gè)倉(cāng)庫(kù)。為保證用戶正常升級(jí),舊鏡像將暫時(shí)保留一段時(shí)間,擇期刪除。

倉(cāng)庫(kù)對(duì)應(yīng)關(guān)系:

github.com/Homebrew/brew -> mirrors.ustc.edu.cn/brew.git
github.com/Homebrew/homebrew-core -> mirrors.ustc.edu.cn/homebrew-core.git
github.com/Homebrew/homebrew(棄用) -> mirrors.ustc.edu.cn/homebrew.git

引自:新增brew.git與homebrew-core.git鏡像

安裝

獲取install文件并編輯

cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

編輯brew_install文件

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/Homebrew/brew/tarball/master anywhere you like or
# change the value of HOMEBREW_PREFIX.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

注釋掉BREW_REPO = "https://github.com/Homebrew/brew".freezeCORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze

修改為BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freezeCORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

安裝

/usr/bin/ruby ~/brew_install 

運(yùn)行修改了的brew_install文件。

替換homebrew源

替換homebrew默認(rèn)源

cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

替換homebrew-core源

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

brew更新

brew update

設(shè)置 bintray鏡像

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

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

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