Homebrew 使用
使用
brew install
brew uninstall|remove|rm
brew list # *显示已安装软件列表
brew upgrade # 更新 Homebrew
brew search # *搜索软件
brew info # *显示软件详细信息
brew help [COMMAND] # 显示命令帮助
brew tap
brew tap-info
man brew # 显示帮助手册
换源
使用镜像源
版本变更信息:
4.3.0
:弃用了homebrew/cask-fonts
和homebrew/cask-versions
库,并将其合并到homebrew/cask
。4.0.0
:软件包信息不再从homebrew/core
和homebrew/cask
库获取,转而从 API (formulae.brew.sh) 获取。相应地,弃用了环境变量HOMEBREW_CORE_GIT_REMOTE
而启用了环境变量HOMEBREW_API_DOMAIN
。
更新 Homebrew git 仓库索引:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" # 指定 Homebrew 自身的 Git 仓库的镜像地址
brew update # 更新索引
设置环境变量,在 .zshrc
中添加以下内容:
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_PIP_INDEX_URL="https://mirrors.ustc.edu.cn/pypi/web/simple"
HOMEBREW_API_DOMAIN
:Homebrew 的 API 地址,用来检索 ruby 文件HOMEBREW_BOTTLE_DOMAIN
:Homebrew 的 bottle 地址,用来下载预编译的二进制包(bottle)HOMEBREW_PIP_INDEX_URL
:Homebrew 中使用的 pip 的索引地址
接下来指定 tap 库的 git 远程仓库地址:
brew tap --custom-remote --force-auto-update "homebrew/command-not-found" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git"
brew tap --custom-remote --force-auto-update "homebrew/services" "https://mirrors.ustc.edu.cn/homebrew-services.git"
恢复为官方源
更新 Homebrew git 仓库索引:
export HOMEBREW_BREW_GIT_REMOTE="https://github.com/Homebrew/brew.git" # 指定 Homebrew 自身的 Git 仓库的镜像地址
brew update # 更新索引
在 .zshrc
中删除以下内容:
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_PIP_INDEX_URL="https://mirrors.ustc.edu.cn/pypi/web/simple"
接下来指定 tap 库的 git 远程仓库地址:
brew tap --custom-remote "homebrew/command-not-found" "https://github.com/Homebrew/homebrew-command-not-found.git"
brew tap --custom-remote "homebrew/services" "https://github.com/Homebrew/homebrew-services.git"
使用镜像源安装 Homebrew
如果你还没有安装 Homebrew,你可以使用下面的命令从镜像源安装 Homebrew:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"
附录:各镜像站参考文档
- Homebrew 源使用帮助 | 中国科学技术大学开源软件镜像
- Homebrew / Linuxbrew 镜像使用帮助 | 清华大学开源软件镜像站
- Homebrew 镜像 | 阿里巴巴开源镜像站
- Homebrew 镜像使用帮助 | 腾讯软件源
- Homebrew Mirror | 南方科技大学开源镜像站
- Homebrew 中文网
tap 仓库
tap
是 Homebrew 的一个扩展机制,可以让用户添加第三方仓库,从而安装第三方仓库中的软件。
brew tap
:用于添加第三方仓库。
brew tap # 查看已添加的仓库
brew tap owner/repo # 添加仓库 owner/homebrew-repo
brew untap owner/repo # 删除仓库
也可以不 tap 仓库直接使用仓库中的 cask:
brew install owner/repo/package
杂项
Formulae 和 Cask 的区别
-
最明显的区别在于 formulae 一般是命令行程序,而 cask 一般是图形化程序。
-
Homebrew Cask 项目:原先是独立于 Homebrew 的一个扩展,提供对以二进制形式发布的 macOS 应用的管理,但现在与 Homebrew 密切合作。
-
Formulae 和 Cask:Homebrew 项目将自己的包定义文件称为 formulae,而 Homebrew Cask 项目将自己的包定义文件称为 cask。它们都是用基于 Ruby 的 DSL 编写的文件,描述如何安装软件。区别在于 formulae 往往提供命令行程序的包定义文件,而 cask 往往提供图形化程序的包定义文件。
-
下载好的 formulae 包会存放在 Homebrew 的
Cellar
子目录下,并且会链接到opt
子目录中。对于 cask 包,则会存放到Caskroom
子目录下。
参见:What is the difference between brew install xxx and brew cask install xxx | Stackoverflow
一些名词解释
- Caveats:注意事项
Troubleshooting
It seems the App source '/Applications/Spotify.app' is not there.
解决方法:
rm -rf /opt/homebrew/Caskroom/spotify
brew install spotify
本文作者:Undefined443
本文链接:https://www.cnblogs.com/Undefined443/p/18206081
版权声明:本作品采用署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步