Homebrew 是 macOS 平台的軟件包管理器,相當於 Linux 常用的 apt-get,zypper,pacman 等。
安裝:
打開終端,逐條執行以下命令
首先需要安裝依賴包 Xcode,彈出來的對話框請一路點擊 OK,過程長短看網速。
xcode-select --install
然后安裝 Homebrew,粘貼到終端里回車即可。(注意這是一整條命令,不同瀏覽方式可能被折行,務必完整復制)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
最后執行這個命令,沒有報錯則可確認安裝成功(一般輸出是 "Your system is ready to brew.")。
brew doctor
這樣海外和已經有系統全局代理設置的朋友們就可以直接使用 brew 命令安裝軟件了。
換源:
直接使用 Homebrew 還需要更改默認源,不然誰用誰想打人,原因你懂的。以下是將默認源替換為國內 USTC 源的方法。
替換核心軟件倉庫
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替換 cask 軟件倉庫(提供 macOS 應用和大型二進制文件)
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替換 Bottles 源(Homebrew 預編譯二進制軟件包)
bash(默認 shell)用戶:
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
基本用法:
假定操作對象為 wget,請替換為自己需要的軟件包名
操作 | 命令 |
更新 Homebrew | brew update |
更新所有安裝過的軟件包 | brew upgrade |
更新指定的軟件包 | brew upgrade wget |
查找軟件包 | brew search wget |
安裝軟件包 | brew install wget |
卸載軟件包 | brew remove wget |
列出已安裝的軟件包 | brew list |
查看軟件包信息 | brew info wget |
列出軟件包的依賴關系 | brew deps wget |
列出可以更新的軟件包 | brew outdated |
參考:
Homebrew 中文主頁
https://brew.sh/index_zh-cn.html
Homebrew Bottles 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-bottles.html
Homebrew Cask 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html
Homebrew Core 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-core.git.html