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

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

First

MBP上的brew很老了,就想把brew更新一下,順便安裝一下NodeJs。無奈更新的過程一直卡在網(wǎng)絡(luò)下載,毫不動彈。想想,應(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 的安裝方法(官方的方法老是安裝失敗) 第三方”這篇文章。

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

國內(nèi)的鏡像

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

由于官方棄用了舊的homebrew倉庫,將homebrew程序與軟件包拆分成了兩個倉庫。為保證用戶正常升級,舊鏡像將暫時保留一段時間,擇期刪除。

倉庫對應(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 

運行修改了的brew_install文件。

替換homebrew源

替換homebrew默認源

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)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容