一、Homebrew
官网:https://brew.sh
Homebrew 主要有四个部分组成:
- brew(源代码仓库)
- homebrew-core (核心软件仓库)
- homebrew-bottles (预编译二进制软件包)
- homebrew-cask (提供 macOS 应用和大型二进制文件)
二、安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
国内小伙伴如果安装不成功,可使用国内镜像安装
# 常规安装
/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
有的小伙伴安装时可能出现如下情况
Cloning into 'brew-install-ck'...
fatal: unable to access 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git/': The requested URL returned error: 403
sed: brew-install-ck/install.sh: No such file or directory
sed: brew-install-ck/install.sh: No such file or directory
sed: brew-install-ck/install.sh: No such file or directory
sed: brew-install-ck/install.sh: No such file or directory
/bin/bash: brew-install-ck/install.sh: No such file or directory
此步骤失败 '调用官方安装失败请查看上方报错信息'
换个网络重新执行上面的命令就好了: 比如用手机给电脑共享一下网络
三、验证
安装完成后,你可以通过运行
brew --version
来验证 Homebrew 是否已正确安装。如果显示了版本号,则表示安装成功。
或者运行以下命令查看是否安装成功
brew install wget
四、卸载
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
常用命令
#查看brew的版本
brew -v
#更新homebrew自己,把所有的Formula目录更新,并且会对本机已经安装并有更新的软件用*标明
brew update
#查看命令帮助:
brew --help
#查看那些已安装的程序需要更新
brew outdated
#更新单个软件:
brew upgrade [包名]
例:brew upgrade git
#更新所有软件:
brew upgrade
#安装软件
brew install [包名]@版本
例:brew install git
#不安装依赖
brew install [包名]@版本 --ignore-dependencies
例:brew install maven --ignore-dependencies 安装Maven时不安装OpenJDK等相关依赖
#卸载
brew uninstall [包名]
#例:brew uninstall git
#清理所有包的旧版本 (安装包缓存)
brew cleanup
例:brew cleanup -n //显示要删除的内容,但不要实际删除任何内容
例:brew cleanup -s //清理缓存,包括下载即使是最新的版本
例:brew cleanup --prune=1 //删除所有早于指定时间的缓存文件(天)
#清理单个软件旧版本
brew cleanup [包名]
例:brew cleanup git
#锁定某个包
brew pin $FORMULA
#取消锁定
brew unpin $FORMULA
#查看包信息
brew info [包名]
#例:brew info git
#查看安装列表
brew list
//查询可用包
brew search [包名]
例:brew search git
#显示包依赖
brew deps [包名]
#例: brew deps git
五 切换国内源
中科大源
# 替换各个源
$ 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
清华源
# 替换各个源
$ 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
阿里源
# 查看 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)
# 修改 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
# 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
重置为官方源
# 重置 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 配置
$ vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# 刷新源
$ brew update