Mac安裝Homebrew

官方

Homebrew是Mac上非常優(yōu)秀的軟件包管理工具。

前提

Mac安裝Homebrew的前提條件

  • 64bit Intel CPU或Apple Silicon CPU(M1)
  • macOS Mojave(10.14)或更高版本
  • 安裝Xcode命令行工具(Command Line Tools for Xcode)
    • 可以通過(guò)命令行xcode-select --install安裝
  • shell(比如bash或zsh)

安裝

打開(kāi)終端,輸入以下命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

其他安裝方法

由于國(guó)內(nèi)的網(wǎng)絡(luò)環(huán)境等問(wèn)題,使用官方的安裝方法可能無(wú)法安裝成功。可以嘗試使用其他更適合國(guó)內(nèi)網(wǎng)絡(luò)環(huán)境的安裝方法,參考地址:https://brew.idayer.com/。

安裝homebrew-core

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"

安裝homebrew-cask

cd "$(brew --repo)/Library/Taps/homebrew/"
 
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git

為了加速以后使用Homebrew安裝其他軟件的過(guò)程,建議設(shè)置軟件源為國(guó)內(nèi)源。

查看源

cd "$(brew --repo)" && git remote -v
 
cd "$(brew --repo homebrew/core)" && git remote -v
 
cd "$(brew --repo homebrew/cask)" && git remote -v

設(shè)置源

設(shè)置為中科大的源

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

設(shè)置bottles鏡像

從macOS Catalina(10.15.x) 版開(kāi)始,Mac使用zsh作為默認(rèn)shell,使用的配置文件:.zprofile

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

如果是以前的macOS版本,Mac使用bash作為默認(rèn)shell,使用的配置文件:.bash_profile

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

重置為官方源

可以通過(guò)以下命令還原回官方源。

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
 
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
 
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
 
# zsh 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置
vi ~/.zprofile
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
source ~/.zprofile
 
# bash 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置
vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
source ~/.bash_profile
 
brew update

卸載

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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