在Linux使用brew(更新版)
安裝前準(zhǔn)備
1. 安裝依賴
- ?Ubuntu ?
sudo apt install build-essential procps curl file git
- ?Fedora ?
sudo dnf groupinstall 'Development Tools'
sudo dnf install curl file git
2. 修改環(huán)境變量
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
安裝
1. 安裝 brew
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git?brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install
2. 添加 PATH 變量
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
3. brew-cask
sudo mkdir -p /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git?/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask
4. 查看源
git -C "$(brew --repo)" remote -v
git -C "$(brew --repo homebrew/core)" remote -v
git -C "$(brew --repo homebrew/cask)" remote -v
5. 官方源
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
brew update
6. 替換源
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
brew update
7. brew-bottles 換源
- bash
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles'?>> ~/.bash_profile
source ~/.bash_profile
- zsh
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles'?>> ~/.zshrc
source ~/.zshrc
8. 查詢版本
brew -v
brew --version
顯示3個(gè)庫(kù)
> Homebrew 3.3.11
> Homebrew/homebrew-core (git revision 34f9503efb7; last commit 2022-01-24)
> Homebrew/homebrew-cask (git revision b0206bb04c; last commit 2022-01-24)
9. 驗(yàn)證
brew doctor
10. 幫助
brew help
man brew
## 對(duì)應(yīng)庫(kù)
1. brew
> https://github.com/Homebrew/brew
> https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
對(duì)應(yīng)位置
> /home/linuxbrew/.linuxbrew/Homebrew/bin/brew
2. brew-croe
> https://formulae.brew.sh/formula/
> https://github.com/Homebrew/homebrew-core
> https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
對(duì)應(yīng)位置
> /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core
3. brew-cask
> https://formulae.brew.sh/cask/
> https://github.com/Homebrew/homebrew-cask
> https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
對(duì)應(yīng)位置
> /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask
4. 主庫(kù)
> https://formulae.brew.sh/
> https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
brew
1. 安裝
> brew install
2. 移除
> brew uninstall
> brew remove
3. 自動(dòng)移除
> brew autoremove
4. 查找(遠(yuǎn)程存儲(chǔ)庫(kù))
> brew search 軟件名
5. 列出(已安裝)
> brew list
6. 更新
> brew update
> brew upgrade
7. 詳細(xì)信息
> brew info
8. 清理(舊版本)
> brew cleanup
9. 查看緩存路徑
> brew --cache
brew cask
1. 安裝
> brew install --cask
2. 列出(已安裝 cask)
> brew list --casks
3. 搜索
> brew search --cask
參考
1. 官方文檔
> https://docs.brew.sh/Homebrew-on-Linux
2. 清華大學(xué)鏡像源
> https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
> https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/
3. 網(wǎng)友博客
> https://www.mintimate.cn/2020/04/05/Homebrew/

PS:macOS與Linux存在一些區(qū)別(特別是cask),安裝路徑也不一樣,不一定適用于Linux。