Mac安装Homebrew
官方
Homebrew是Mac上非常优秀的软件包管理工具。
前提
Mac安装Homebrew的前提条件:
- 64bit Intel CPU或Apple Silicon CPU(M1)
- macOS Mojave(10.14)或更高版本
- 安装Xcode命令行工具(Command Line Tools for Xcode)
- 可以通过命令行xcode-select --install安装
- shell(比如bash或zsh)
安装
打开终端,输入以下命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
其他安装方法
由于国内的网络环境等问题,使用官方的安装方法可能无法安装成功。可以尝试使用其他更适合国内网络环境的安装方法,参考地址:https://brew.idayer.com/。
安装homebrew-core
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
安装homebrew-cask
cd "$(brew --repo)/Library/Taps/homebrew/" git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
源
为了加速以后使用Homebrew安装其他软件的过程,建议设置软件源为国内源。
查看源
cd "$(brew --repo)" && git remote -v cd "$(brew --repo homebrew/core)" && git remote -v cd "$(brew --repo homebrew/cask)" && git remote -v
设置源
设置为中科大的源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git brew update
设置bottles镜像
从macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认shell,使用的配置文件:.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zprofile source ~/.zprofile
如果是以前的macOS版本,Mac使用bash作为默认shell,使用的配置文件:.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile
重置为官方源
可以通过以下命令还原回官方源。
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git # zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 vi ~/.zprofile # export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles source ~/.zprofile # bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 vi ~/.bash_profile # export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles source ~/.bash_profile brew update
卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构