前言:筆者是個Java程式員,使用Windows系統開發5年多左右,最近換了台MacBook Pro,因為系統不同的緣故,故此将我的踩坑記錄起來做總結。另外希望我所做的記錄能夠對大家有幫助。
系統版本:mac os 10.14.3
注意事項:Homebrew的國外鏡像位址用不了,需要換成國内的才行。(這是個大坑,這個我找了不少資料)
一、Homebrew到底是什麼個東西?
linux系統有個讓人頭疼的通病,那就是軟體包依賴,好在目前主流的兩大發行版本都自帶了解決方案,Red hat有yum,Ubuntu有apt-get。那麼我們用Mac OSx系統怎麼辦?别擔心,這一切Homebrew可以幫你搞定。
Homebrew是一款Mac OS平台下的軟體包管理工具,擁有安裝、解除安裝、更新、檢視、搜尋等很多實用的功能。簡單的一條指令,就可以實作包管理,而不用你關心各種依賴和檔案路徑的情況,十分友善快捷。
更通俗點的解釋就是:Homebrew就好比一個應用商店,而唯一不同的應用商店提供了可視化視圖 ,采用的是普通安裝模式。而Homebrew則采用的自動安裝模式,隻需要輸入指令即可完成自動安裝。
二、開始安裝Homebrew
1.擷取install檔案并編輯,下面指令執行後,brew_install檔案被下載下傳到了目前使用者檔案下面
cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
編輯的話直接在Finder裡面搜尋brew_install,輕按兩下之後打開,一般會用Xcode打開。原文說的“注釋掉BREW_REPO = "https://github.com/Homebrew/brew".freeze和CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze”,不知為何,我這兒沒有CORE_TAP_REPO這一行,不過沒關系,新增上去就行了。
修改後代碼和截圖如下
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/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 = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze#新增
2.開始安裝
/usr/bin/ruby ~/brew_install
3.替換源
#替換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
4.brew更新
brew update
最後:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
說明:本文部分内容參考網絡,如果侵權請聯系删除。
感謝下面作者給予的參考。
參考處位址:https://segmentfault.com/a/1190000018360813