目錄
- 安裝
- 修改homeBrew源
- 常用命令
- 安裝卸載軟件
- 升級軟件相關
- 清理相關
安裝
- 官網
- https://brew.sh/
- 不推薦官網安裝方式(很慢很慢或者安裝失敗聯網失敗)
- 檢測是否安裝homebrew
brew -v
- 執行安裝命令
- 蘋果電腦 常規安裝腳本 (推薦 完全體 幾分鐘就安裝好)
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
- 蘋果電腦 極速安裝腳本(精簡版 幾秒鐘安裝完成)
常規安裝過程如下:/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed
- 重啟終端或者運行以下代碼
source /User/admin/.zprofile
- 卸載指令
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
修改homeBrew源
- 替換為阿里源
# 查看 brew.git 當前源
cd "$(brew --repo)" && git remote -v
# origin https://github.com/Homebrew/brew.git (fetch)
# origin https://github.com/Homebrew/brew.git (push)# 查看 homebrew-core.git 當前源
cd "$(brew --repo homebrew/core)" && git remote -v
# origin https://github.com/Homebrew/homebrew-core.git (fetch)
# origin https://github.com/Homebrew/homebrew-core.git (push)# 查看 homebrew-cask.git 當前源
cd "$(brew --repo homebrew/core)" && git remote -v
# origin https://github.com/Homebrew/homebrew-cask.git (fetch)
# origin https://github.com/Homebrew/homebrew-cask.git (push)# 修改 brew.git 為阿里源
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git# 修改 homebrew-core.git 為阿里源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git#修改 homebrew-cask.git 為阿里源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git# zsh 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrcsource ~/.zshrc# bash 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profilesource ~/.bash_profile# 刷新源
brew update
- 替換為清華源
# 替換各個源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git# zsh 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrcsource ~/.zshrc# bash 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profilesource ~/.bash_profile
# 刷新源
brew update
- 替換為中科大源
# 替換各個源
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# zsh 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrcsource ~/.zshrc# bash 替換 brew bintray 鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profilesource ~/.bash_profile# 刷新源
brew update
- 重置為官方源
# 重置 brew.git 為官方源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git# 重置 homebrew-core.git 為官方源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git# 重置 homebrew-cask.git 為官方源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask# zsh 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置,其實就是加個#,也可用nano
vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx# bash 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置,其實就是加個#,也可用nano
vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx# 刷新源
brew update
常用命令
安裝卸載軟件
brew --version
或者 brew -v
顯示 brew
版本信息
brew install <formula>
安裝指定軟件
brew uninstall <formula>
卸載指定軟件
brew list
顯示所有的已安裝的軟件
brew search text
搜索本地遠程倉庫的軟件,已安裝會顯示綠色的勾
brew search /text/
使用正則表達式搜軟件
brew info <formula>
顯示指定軟件信息
brew reinstall <formula>
重新安裝指定軟件,先卸載后安裝
brew install <formula> --build-from-source
源碼安裝指定軟件,可以給定指定參數
brew commands
列出所有可用命令
升級軟件相關
brew update
自動升級 homebrew (從 github 下載最新版本)
brew outdated
檢測已經過時的軟件
brew upgrade 升級所有已過時的軟件,即列出的以過時軟件
brew upgrade 升級指定的軟件
brew pin 禁止指定軟件升級 ``brew unpin <formula>
解鎖禁止升級
brew upgrade --all
升級所有的軟件包,包括未清理干凈的舊版本的包
brew edit <formula>
編輯軟件,不會的情況下慎用
brew tap
列出本地資源倉庫,其中 homebrew 是默認倉庫,其它都是第三方倉庫
brew tap <user/repo>
添加第三方倉庫,命名的規則按照 github 來定的。使用
brew untap <user/repo>
刪除倉庫
brew deps <formula>
查看指定軟件依賴于哪些軟件
brew uses <formula>
查看指定軟件被哪些軟件所依賴
清理相關
homebrew
再升級軟件時候不會清理相關的舊版本,在軟件升級后我們可以使用如下命令清理
brew cleanup -n
列出需要清理的內容
brew cleanup <formula>
清理指定的軟件過時包
brew cleanup
清理所有的過時軟件
brew unistall <formula>
卸載指定軟件
brew unistall <fromula> --force
徹底卸載指定軟件,包括舊版本
通過 brew
安裝的文件會自動設置環境變量,所以不用擔心命令行不能啟動的問題。
比如安裝好了 gradle
,即可運行 gradle -v