MacOS 安装 Homebrew

Homebrew:The missing package manager for macOS。

Homebrew 是苹果系统的扩展包安装工具,可以以非常优雅的方式安装 MariaDB,Redis、等工具。下面就是安装Homebrew的教程,本教程使用国内的清华镜像作为Homebrew镜像源,这样可以改善软件下载速度,提升使用体验。

1 首先需要安装Command Line Tools (CLT) for Xcode

安装Command Line Tools (CLT) for Xcode的目的是为MacOS添加命令工具:git 和 curl

打开Mac的终端

 

在终端中输入命令,安装Command Line Tools (CLT) for Xcode

xcode-select --install

2 安装Homebrew

在终端输入以下几行命令设置环境变量,设定使用清华Homebrew镜像源:

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_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"

然后,在终端运行以下命令以安装 Homebrew:

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

3 Apple Silicon CPU 设备上的 macOS 系统

如果您设备是Apple Silicon CPU 设备上的 macOS 系统,则需要设置进行如下设置,如果是Intel CPU 系统则跳过这步。

在终端输入命令检查处理器类型:

uname -m

如果得到:

arm64

则说明您使用的是 Apple Silicon CPU 设备上的 macOS 系统(ARM 处理器)需要进行如下设置:

touch ~/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
touch ~/.zprofile 
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

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

4 替换现有仓库

Homebrew默认仓库在境外,访问非常慢,替换为国内镜像仓库可以大大加快访问速度,这里设置是是清华镜像仓库,可以替换 brew 程序本身的源:

export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
for tap in core cask{,-fonts,-drivers,-versions} command-not-found; do
    brew tap --custom-remote --force-auto-update "homebrew/${tap}" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git"
done
brew update

然后设置系统环境变量,如果用户设置了环境变量 HOMEBREW_BREW_GIT_REMOTE 和 HOMEBREW_CORE_GIT_REMOTE,则每次执行 brew update 时,brew 程序本身和 Core Tap (homebrew-core) 的远程将被自动设置。推荐用户将这两个环境变量设置加入 shell 的 profile 设置中,并且也需要设置HOMEBREW_BOTTLE_DOMAIN 支持bottle库:

touch ~/.bash_profile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.bash_profile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.bash_profile
touch ~/.zprofile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofile

如果您熟悉 vim 等编辑器,您可以手动编辑 .zprofile 或者 .bash_profile文件。

如果您使用的是 bash 编辑.bash_profile即可

如果您使用的是 zsh 编辑.zprofile即可

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
macOS安装Homebrew非常简单。你可以按照以下步骤进行安装: 1. 打开终端应用程序。 2. 在终端中输入以下命令并按下回车键,以安装Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` 注意:如果以上链接失效,你可以在Homebrew的官方网站上查找最新的安装命令链接。 3. 终端会提示你输入管理员密码,输入密码后按下回车键继续。 4. 等待安装过程完成,安装过程可能需要一些时间,取决于你的网络连接速度。 5. 安装完成后,你可以通过在终端中输入以下命令来验证Homebrew是否成功安装: ``` brew --version ``` 如果你看到Homebrew的版本信息,则表示安装成功。 现在你已经成功在macOS安装Homebrew,你可以使用它来搜索、安装和卸载各种软件包。例如,你可以使用`brew search 软件名`来搜索软件包,使用`brew install 软件名`来安装软件包,使用`brew uninstall 软件名`来卸载软件包,使用`brew update`来更新Homebrew,使用`brew config`来查看Homebrew的配置信息。 希望这些信息对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [MacOS安装Homebrew](https://blog.csdn.net/qq_43783527/article/details/125242300)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [macOS安装Homebrew](https://blog.csdn.net/q383965374/article/details/80404314)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nia134

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值