目录
安装
- 官网 
  - https://brew.sh/
- 不推荐官网安装方式(很慢很慢或者安装失败联网失败)
 
- 检测是否安装homebrewbrew -v 
- 执行安装命令 
  - 苹果电脑 常规安装脚本 (推荐 完全体 几分钟就安装好)
 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"- 苹果电脑 极速安装脚本(精简版 几秒钟安装完成)
 
 常规安装过程如下:/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed
  
  
  
  
- 重启终端或者运行以下代码source /User/admin/.zprofile 
- 卸载指令/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
修改homeBrew源
- 替换为阿里源
# 查看 brew.git 当前源
cd "$(brew --repo)" && git remote -v
# origin    https://github.com/Homebrew/brew.git (fetch)
# origin    https://github.com/Homebrew/brew.git (push)
# 查看 homebrew-core.git 当前源
cd "$(brew --repo homebrew/core)" && git remote -v
# origin    https://github.com/Homebrew/homebrew-core.git (fetch)
# origin    https://github.com/Homebrew/homebrew-core.git (push)
# 查看 homebrew-cask.git 当前源
cd "$(brew --repo homebrew/core)" && git remote -v
# origin    https://github.com/Homebrew/homebrew-cask.git (fetch)
# origin    https://github.com/Homebrew/homebrew-cask.git (push)
# 修改 brew.git 为阿里源
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 修改 homebrew-core.git 为阿里源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
#修改 homebrew-cask.git 为阿里源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
# zsh 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# bash 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 刷新源
brew update
- 替换为清华源
# 替换各个源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# zsh 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# bash 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 刷新源
brew update
- 替换为中科大源
# 替换各个源
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
# zsh 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# bash 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 刷新源
brew update
- 重置为官方源
# 重置 brew.git 为官方源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 重置 homebrew-core.git 为官方源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 重置 homebrew-cask.git 为官方源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
# zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置,其实就是加个#,也可用nano
vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置,其实就是加个#,也可用nano
vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# 刷新源
brew update
常用命令
安装卸载软件
brew --version 或者 brew -v 显示 brew 版本信息
 brew install <formula> 安装指定软件
 brew uninstall <formula> 卸载指定软件
 brew list 显示所有的已安装的软件
 brew search text 搜索本地远程仓库的软件,已安装会显示绿色的勾
 brew search /text/ 使用正则表达式搜软件
 brew info <formula> 显示指定软件信息
 brew reinstall <formula> 重新安装指定软件,先卸载后安装
 brew install <formula> --build-from-source 源码安装指定软件,可以给定指定参数
 brew commands 列出所有可用命令
升级软件相关
brew update 自动升级 homebrew (从 github 下载最新版本)
 brew outdated 检测已经过时的软件
 brew upgrade 升级所有已过时的软件,即列出的以过时软件 brew upgrade 升级指定的软件brew pin 禁止指定软件升级 ``brew unpin <formula>解锁禁止升级
 brew upgrade --all 升级所有的软件包,包括未清理干净的旧版本的包
 brew edit <formula> 编辑软件,不会的情况下慎用
 brew tap 列出本地资源仓库,其中 homebrew 是默认仓库,其它都是第三方仓库
 brew tap <user/repo> 添加第三方仓库,命名的规则按照 github 来定的。使用
 brew untap <user/repo> 删除仓库
 brew deps <formula> 查看指定软件依赖于哪些软件
 brew uses <formula> 查看指定软件被哪些软件所依赖
清理相关
homebrew 再升级软件时候不会清理相关的旧版本,在软件升级后我们可以使用如下命令清理
brew cleanup -n 列出需要清理的内容
 brew cleanup <formula> 清理指定的软件过时包
 brew cleanup 清理所有的过时软件
 brew unistall <formula> 卸载指定软件
 brew unistall <fromula> --force 彻底卸载指定软件,包括旧版本
通过 brew 安装的文件会自动设置环境变量,所以不用担心命令行不能启动的问题。
 比如安装好了 gradle,即可运行 gradle -v









