MacOS 安裝 HomeBrew

Homebrew是一款自由及開放源代碼的軟件包管理系統,用以簡化macOS系統上的軟件安裝過程。對于Appstore中沒有的軟件,推薦使用此方法安裝管理第三方軟件。


一、官方安裝Homebrew

網址:https://brew.sh/

中文網址:https://brew.sh/index_zh-cn

命令:

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

卸載:

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

二、國內鏡像安裝方法

1)獲取install文件

獲取官網腳本并保存名為 brew_install:raw.githubusercontent.com/Homebrew/install/master/install

2)替換成清華大學的鏡像

打開 brew_install 文件,修改如下:

找到如下代碼:

BREW_REPO = “https://github.com/Homebrew/brew“.freeze

CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze

更改為:

BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze

CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze

注意: 新版本HomeBrew可能沒有CORE_TAP_REPO這句代碼,如果沒有不用新增。 如果這個鏡像有問題的話,可以換成其他源(如中科大,下面有寫)。

3)執行腳本

打開終端允許腳本

/usr/bin/ruby brew_install

如果此時腳本應該停在

==> Tapping homebrew/core

Cloning into'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

出現這個原因是因為源不通,代碼來不下來,解決方法就是更換國內鏡像源:

手動執行下面這句命令,更換為中科院的鏡像:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

然后把homebrew-core的鏡像地址也設為中科院的國內鏡像

cd "$(brew --repo)"

git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

執行更新,成功:

brew update

最后用這個命令檢查無錯誤:

brew doctor

至此HomeBrew就安裝完成了。


三、切換默認源

*** 使用代理:使用代理可以不用切換源

brew支持全局socks代理。使用前加上這一句:

export ALL_PROXY=socks5://127.0.0.1:portnumber

portnumber 是代理端口號

1)中科大源

?替換 Homebrew

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

替換 Homebrew Core

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

替換 Homebrew Cask

git -C"$(brew --repo homebrew/cask)"remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

brew update?

替換 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

2)清華源

替換 Homebrew

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git?

替換 Homebrew Core

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

替換 Homebrew Cask

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

brew update

替換 Homebrew-bottles

?對于 bash 用戶:

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

source ~/.bash_profile

3)官方源

替換 Homebrew

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

替換 Homebrew Core

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

替換 Homebrew Cask

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

brew update

替換 Homebrew-bottles

注釋掉bash配置文件里的有關Homebrew Bottles即可恢復官方源。 重啟bash或讓bash重讀配置文件。

或 (未測試)

對于 bash 用戶:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://homebrew.bintray.com/bottles/homebrew-bottles' >> ~/.bash_profile

source ~/.bash_profile


四、常用命令

搜索軟件

brew search 軟件名

安裝軟件

brew install 軟件名

卸載軟件

brew uninstall 軟件名

更新全部軟件

brew update

更新指定軟件

brew upgrade 軟件名

顯示已安裝軟件

brew list

brew list 軟件名? ?//查看某軟件安裝路徑

查看哪些軟件需要更新

brew outdated

查看幫助

brew help

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。