本文阅读量 117 次
1. Brew 用法¶
1.1 核心概念¶
概念 | 全称 | 备注 |
---|---|---|
Bottles | Binary Packages | https://docs.brew.sh/Bottles ⧉ |
Taps | Third-Party Repositories | https://docs.brew.sh/Taps ⧉ |
1.2 基本使用¶
1.2.1 查看所有命令¶
brew commands
➜ ~ brew commands
==> Built-in commands
--cache analytics deps gist-logs list pin search untap
--caskroom autoremove desc help log postgresql-upgrade-database shellenv update-report
--cellar casks developer home migrate postinstall tap-info update-reset
--env cleanup docs info missing pyenv-sync tap update
--prefix commands doctor install nodenv-sync rbenv-sync uninstall upgrade
--repository completions fetch leaves options readall unlink uses
--version config formulae link outdated reinstall unpin vendor-install
==> Built-in developer commands
audit bump dispatch-build-bottle generate-man-completions pr-publish ruby typecheck update-sponsors
bottle cat edit install-bundler-gems pr-pull sh unbottled update-test
bump-cask-pr command extract irb pr-upload style unpack vendor-gems
bump-formula-pr contributions formula linkage prof tap-new update-license-data
bump-revision create generate-cask-api livecheck release test update-maintainers
bump-unversioned-casks determine-test-runners generate-formula-api pr-automerge rubocop tests update-python-resources
==> External commands
aspell-dictionaries check-ci-status determine-rebottle-runners services
1.2.2 直接从命令行打开官方文档¶
brew docs
1.2.3 安装软件¶
brew install
1.2.4 搜索软件¶
brew search
1.2.5 查看已经安装的列表¶
brew list
brew outdated
1.2.6 查看某个软件信息¶
brew info <aaa>
1.2.7 更新¶
brew update
1.2.8 升级¶
brew upgrade
1.2.9 检查环境¶
brew doctor
1.2.10 如何升级 brew 自身¶
TODO
1.3 后台服务管理¶
brew services list: 查看所有服务
brew services run [服务名]: 单次运行某个服务
brew services start [服务名]: 运行某个服务,并设置开机自动运行。
brew services stop [服务名]:停止某个服务
brew services restart:重启某个服务。
1.4 Brew Taps¶
命令 | 说明 | 备注 |
---|---|---|
brew tap | 列出当前已经安装的 tap | |
brew tap-info <user/repo> | 查看某个 tap 的信息 | 本地安装目录,远端 |
brew tap <user/repo> | 从 Github 安装 | |
brew tap <user/repo> <URL> | 从 | |
brew untap <user/repo> | 移除 tap,支持指定多个 tap | |
brew tap-new | 创建新的 tap |
➜ ~ brew tap-info spring-io/tap
spring-io/tap: 1 formula
/opt/homebrew/Library/Taps/spring-io/homebrew-tap (94 files, 101.1KB)
From: https://github.com/spring-io/homebrew-tap
1.4.1 如果 三方 tap 中的 formulae 和核心库的 formulae 冲突¶
brew 按照如下顺序进行搜索并安装
- 核型 formulae
- 其它三方 taps
如果想要安装三方 taps 中相同名字的 formulae,可以在命令中显示指定对应的 tap
brew install vim # 安装 homebrew/core 中的 vim
brew install username/repo/vim # 安装 username/repon 中的 vim
1.5 自定义命令¶
1.6 其他¶
brew info --all
1.6.1 如何设置国内代理¶
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_CORE_GIT_REMOTE=https://mirrors.ustc.edu.cn/homebrew-core.git
1.6.1.1 使用中科大镜像¶
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
1.6.1.2 使用清华镜像¶
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
1.6.1.3 恢复默认¶
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
1.7 相关环境变量¶
环境变量 | 说明 |
---|---|
HOMEBREW_BOTTLE_DOMAIN | |
HOMEBREW_BREW_GIT_REMOTE | |
HOMEBREW_CORE_GIT_REMOTE | |
HOMEBREW_NO_INSTALL_FROM_API | |
HOMEBREW_GITHUB_API_TOKEN | |
BREW_REPO |
1.8 FAQ¶
1.8.1 安装 git 失败,更新提示 No remote 'origin' ...¶
➜ workspace_fe brew install git
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
==> Fetching dependencies for git: pcre2
==> Fetching pcre2
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/pcre2-10.42.arm64_ventura.bottle.tar.gz
Already downloaded: /Users/liuhua/Library/Caches/Homebrew/downloads/6c8963b44d5ffe8d641d5e75b8f7e1072e71132a7fb9a0190d8ede46f37486f9--pcre2-10.42.arm64_ventura.bottle.tar.gz
==> Fetching git
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/git-2.41.0.arm64_ventura.bottle.tar.gz
Already downloaded: /Users/liuhua/Library/Caches/Homebrew/downloads/e4dd85511f51c8cd24533ec79ff4f1e4714566484f3ad294ff5e3a4f579f1b85--git-2.41.0.arm64_ventura.bottle.tar.gz
==> Installing dependencies for git: pcre2
==> Installing git dependency: pcre2
fatal: not in a git directory
Error: Command failed with exit 128: git
➜ workspace_fe brew update
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Already up-to-date.
1.8.1.1 解决办法¶
brew doctor
然后按照提示
rm -rf "/opt/homebrew/Library/Taps/homebrew/homebrew-core"
brew tap homebrew/core
rm -rf "/opt/homebrew/Library/Taps/homebrew/homebrew-cask"
brew tap homebrew/cask
1.9 参考¶
- https://docs.brew.sh/ ⧉
- https://docs.brew.sh/Formula-Cookbook ⧉
- https://docs.brew.sh/Cask-Cookbook ⧉
- https://github.com/Homebrew/brew/tree/HEAD/Library/Homebrew/cmd ⧉
- https://github.com/Homebrew/brew/tree/HEAD/Library/Homebrew/dev-cmd ⧉
- https://docs.brew.sh/Taps ⧉
- https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap ⧉
- https://docs.brew.sh/External-Commands ⧉
- 接口文档 https://formulae.brew.sh/docs/api/ ⧉
- 查看所有的 Formulae https://formulae.brew.sh/formula/ ⧉
- 查看所有的 Casks https://formulae.brew.sh/cask/ ⧉
- https://sspai.com/post/56009 ⧉
- https://www.unixtutorial.org/brew-cask-vs-brew-formula/ ⧉
- https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/ ⧉
- https://zhuanlan.zhihu.com/p/337940933 ⧉
- 清华开源设置 https://mirror.tuna.tsinghua.edu.cn/help/homebrew/ ⧉