Homebrew 镜像

简介

Homebrew 是一款自由及开放源代码的软件包管理系统,用以简化 macOS 系统上的软件安装过程。它拥有安装、卸载、更新、查看、搜索等很多实用的功能,通过简单的一条指令,就可以实现包管理,十分方便快捷。

镜像地址:https://mirrors.aliyun.com/homebrew/

要求 Homebrew ≥ 4.0(brew -v 查看版本)。

配置方法

安装 Homebrew

# 使用镜像的安装脚本(推荐,内网可用)
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"
/bin/bash -c "$(curl -fsSL https://mirrors.aliyun.com/homebrew/install.sh)"

# 或从 GitHub 获取官方安装脚本(需能访问 github.com)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装完成后按提示将 brew 加入 PATH。

查看 Homebrew 版本

brew -v

设置 Homebrew 安装源为阿里源

临时替换(仅当前终端会话生效):

export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles/api"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"
brew update

永久替换:

# bash 用户
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles/api"' >> ~/.bash_profile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"' >> ~/.bash_profile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"' >> ~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"' >> ~/.bash_profile
source ~/.bash_profile
brew update

# zsh 用户
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles/api"' >> ~/.zshrc
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"' >> ~/.zshrc
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"' >> ~/.zshrc
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"' >> ~/.zshrc
source ~/.zshrc
brew update

配置 tap 仓库(非必需,非开发者无需配置)

# 绝大部分用户无需额外配置 tap 仓库
# 如需使用 Homebrew 的开发命令,可按如下命令配置 homebrew/core 和 homebrew/cask 镜像
brew tap -v --custom-remote --force-auto-update homebrew/core https://mirrors.aliyun.com/homebrew/homebrew-core.git
brew tap -v --custom-remote --force-auto-update homebrew/cask https://mirrors.aliyun.com/homebrew/homebrew-cask.git

# 其他 tap 仓库按需配置
brew tap -v --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.aliyun.com/homebrew/homebrew-command-not-found.git
brew tap -v --custom-remote --force-auto-update homebrew/services https://mirrors.aliyun.com/homebrew/homebrew-services.git

恢复默认配置

unset HOMEBREW_API_DOMAIN HOMEBREW_BOTTLE_DOMAIN
unset HOMEBREW_BREW_GIT_REMOTE HOMEBREW_CORE_GIT_REMOTE

brew tap --custom-remote homebrew/core https://github.com/Homebrew/homebrew-core.git
brew tap --custom-remote homebrew/cask https://github.com/Homebrew/homebrew-cask.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

brew update

如果之前永久配置了 HOMEBREW 环境变量,还需要从 ~/.bash_profile 或 ~/.zshrc 中删除对应的 export 行。

相关链接

特别声明:本镜像站内容来自第三方网站,阿里云会尽力审核镜像内容安全,但无法保证其完全合规,请您在下载前慎重考虑。具体请查看《阿里云开发者社区用户服务协议》、《阿里云镜像站特别条款》等。 如您发现镜像站有任何问题,可以填写镜像站投诉表单举报,我们将按照法律规定尽快进行处理。