# macos 如何安装homebrew

**URL:** <https://forum.beginner.center/t/topic/2940>\
**Category:** 🛠工具与编程\
**Tags:** homebrew\
**Created:** [2026 年7 月 15 日 09:31 UTC](https://forum.beginner.center/t/topic/2940 "2026-07-15T09:31:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![doggie](https://forum.beginner.center/user_avatar/forum.beginner.center/doggie/32/550_2.png) [@doggie](https://forum.beginner.center/u/doggie)\
发布日期： [2026 年7 月 15 日 09:31 UTC](https://forum.beginner.center/t/topic/2940/1 "2026-07-15T09:31:31Z")

</div>

首先，需要确保系统中安装了 bash、git 和 curl，macOS自带bash、git、 额外安装`Command Line Tools for Xcode`即可

- 终端输入`xcode-select --install` 安装

接着，在终端输入以下几行命令设置环境变量：

```auto
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_INSTALL_FROM_API=1

```

最后，在终端运行以下命令以安装 Homebrew

```auto
# 从镜像下载安装脚本并安装 Homebrew / Linuxbrew
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

# 也可从 GitHub 获取官方安装脚本安装 Homebrew / Linuxbrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

```

**安装成功后需将 brew 程序的相关路径加入到环境变量中：**

基于 Intel CPU 设备上的 macOS 系统（命令行运行 `uname -m` 应输出 `x86_64`）的用户可跳过本步。

基于 Apple Silicon（m系列芯片）macOS 系统（命令行运行 `uname -m` 应输出 `arm64`）

```auto
test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

```
