macOS 安装 Homebrew 教程:多种方式与国内镜像加速

推荐镜像:

Homebrew 是 macOS 上最受欢迎的包管理工具,它让你能够便捷地安装、更新和管理各种软件包。本文将介绍多种安装方式,并提供国内镜像加速方案。

一、什么是 Homebrew?

Homebrew 是 macOS 上最受欢迎的包管理工具,它让你能够便捷地安装、更新和管理各种软件包。

二、安装前准备

  1. 确保系统要求:

    • macOS Monterey (12.0) 或更高版本
    • 已安装 Command Line Tools (CLT)
  2. 安装 Command Line Tools:

xcode-select --install

三、安装方式

1. 国内镜像安装(推荐)

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

2. 官方安装脚本

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3. Git 克隆安装

sudo git clone https://github.com/Homebrew/brew /opt/homebrew

四、配置国内镜像源

1. 中科大镜像

# 替换 brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git

# 替换 homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 替换 homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

2. 清华大学镜像

# 替换 brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替换 homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

# 替换 homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

五、验证安装

# 查看 Homebrew 版本
brew --version

# 检查 Homebrew 状态
brew doctor

六、常见问题解决

  1. 权限问题
sudo chown -R $(whoami) $(brew --prefix)/*
  1. 更新 Homebrew
brew update
  1. 重置镜像源(恢复官方源)
# 重置 brew.git
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# 重置 homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 重置 homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

七、总结

本文介绍了在 macOS 上安装 Homebrew 的多种方式,并提供了国内镜像加速方案。建议国内用户使用镜像安装和配置镜像源,可以显著提升下载速度。如果遇到问题,可以参考常见问题解决方案或查看官方文档。

参考资料

posted @   it非鱼  阅读(1250)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示