MacOS (Apple芯片) 安装 Homebrew 教程

MacOS (Apple芯片) 安装 Homebrew 教程
Homebrew 是 MacOS 上最受欢迎的包管理器,本文将指导您在搭载 Apple 芯片的 Mac 上安装 Homebrew。
准备工作
- 打开”终端”应用程序
- 安装过程中请保持终端窗口打开
- 避免同时打开多个终端窗口,以防止环境变量混淆
安装步骤
1. 安装基础命令工具
首先需要安装 git、curl 等基础命令工具。在终端中执行:
1 | xcode-select --install |
2. 配置 Homebrew 镜像源
为了加快下载速度,我们使用清华大学的镜像源。在终端中执行:
1 | export HOMEBREW_BREW_GIT_REMOTE="http://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git" |
3. 安装 Homebrew
执行以下命令安装 Homebrew:
1 | git clone --depth=1 http://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install |
4. 配置环境变量
根据您使用的 shell 类型,执行相应的命令:
对于 bash 用户:
1 | test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile |
对于 zsh 用户:
1 | test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile |
5. 配置国内镜像源
执行以下命令配置 Homebrew 使用国内镜像:
1 | export HOMEBREW_BREW_GIT_REMOTE="http://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git" |
6. 永久配置镜像源
为了确保重启后镜像源配置仍然生效,需要将配置添加到配置文件中:
对于 bash 用户:
1 | test -r ~/.bash_profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="http://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.bash_profile |
对于 zsh 用户:
1 | test -r ~/.zprofile && echo 'export HOMEBREW_BREW_GIT_REMOTE="http://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofile |
验证安装
安装完成后,您可以通过以下命令验证 Homebrew 是否安装成功:
1 | brew --version |
如果显示版本号,则说明安装成功。
注意事项
- 安装过程中请保持网络连接稳定
- 如果遇到权限问题,可能需要使用
sudo
执行某些命令 - 安装完成后建议重启终端,以确保环境变量生效
现在您已经成功安装了 Homebrew,可以开始使用它来安装各种软件包了!
- 标题: MacOS (Apple芯片) 安装 Homebrew 教程
- 作者: wxh
- 创建于 : 2025-03-21 00:00:00
- 更新于 : 2025-04-13 20:30:09
- 链接: https://blog.private-line.org/2025/03/21/MacOS安装Brew/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论