Mac下使用國內鏡像安裝Homebrew

根據官網上的方法,在終端輸入:html

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

結果仍是被卡在下載階段,怎麼辦呢?因而上網搜索到了「Homebrew 的安裝方法(官方的方法總是安裝失敗) 第三方」這篇文章。git

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

國內的鏡像

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

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

倉庫對應關係:curl

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.gitui

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

安裝

獲取install文件並編輯

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

編輯brew_install文件spa

#!/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.net

修改成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

設置 bintray鏡像

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile 
 

做者:採姑娘的小魔鈷連接:https://www.jianshu.com/p/6523d3eee50d

相關文章
相關標籤/搜索