2023最新总结,Mac下使用Homebrew完全指南!
2023最新总结,Mac下使用Homebrew完全指南!
1. 介绍
Homebrew是一款包管理工具,目前支持macOS和Linux系统。主要有四个部分组成:brew、homebrew-core 、homebrew-cask、homebrew-bottles。

2. 安装
2.1 执行安装脚本
执行/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
,镜像选阿里巴巴,傻瓜式安装,30分钟左右,安装完成。
2.2 验证安装成功
执行brew --version
验证是否安装成功。
2.3 更换下载源
2.3.1 更换brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 中科大
或
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git # 阿里巴巴
或
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git # 清华大学
2.3.2 更换homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 中科大
或
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git # 阿里巴巴
或
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git # 清华大学
2.3.3 更换homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git # 中科大
或
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git # 阿里巴巴
或
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git # 清华大学
2.3.4 更换homebrew-bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile # 阿里云
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile # 中科大
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile # 清华大学
source ~/.bash_profile
如果终端使用的是zsh,就写入zsh的配置文件中。
2.3.5 更新软件包
执行brew update
,如果可以更新成功,更换的源可用。
2.4 恢复默认源
某些情况下,可能我们使用的国内源挂掉了,就需要恢复默认源。
1. git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
2. git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
3. git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
4. 删除环境变量 HOMEBREW_BOTTLE_DOMAIN
5. source ~/.bash_profile
6. brew update
3. 意外处理
- 先执行
brew doctor
查看问题,按照指示对问题进行修复 - 执行
brew update-reset
将homebrew还原到稳定版 - 执行
brew update
更新软件包
4. 常用命令
4.1 安装软件
brew install node
默认安装最新版brew install node@14.16.8
安装指定版本brew switch node 16.0.0
切换版本
4.2 更新软件
brew upgrade name
更新安装过的软件(如果不加软件名,就更新所有可以更新的软件)
4.3 卸载软件
brew uninstall node
卸载node
4.4 服务相关
brew services list
获取services列表brew services start/stop/restart serverName
brew services start mysql
启动mysql服务brew services restart mysql
重启mysql服务brew services stop mysql
停止mysql服务
4.5 其他常用命令
brew config
查看brew配置brew info node
查看node安装信息brew list
查看已安装软件brew list --versions
查看已安装软件版本号brew search node
搜索可用node相关软件brew update
brew自身更新brew cleanup
清除下载的缓存brew doctor
诊断brew,并给出修复命令
5. 卸载Homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
6. 参考
结语
我是滚石,一名热爱前端的前端菜鸟程序员,成长路上,欢迎一起交流讨论,一起进步!
社区优质文章分享、提效轮子、进阶面试题、瓶颈期方向指导、性能优化、常用工具、网站分享、原理解析等涨薪话题,期待你的加入!
关注公众号:滚石的前端成长之路
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· 一个费力不讨好的项目,让我损失了近一半的绩效!
2018-09-09 Use Laravel/homestead 环境维护基于 brophp 开发的老项目