homebrew安装
安装
已废弃
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
brew doctor
国内镜像
https://www.cnblogs.com/beyondmch/articles/8331478.html
https://www.jianshu.com/p/dee2e61dcb70
pod repo add master https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
设置国外镜像
git -C "/usr/local/Homebrew" remote set-url origin https://github.com/Homebrew/brew
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" remote set-url origin https://github.com/Homebrew/homebrew-core
两种方式来解决:
一、直接关闭brew执行命令时的自动更新
# 1. 编辑配置文件
vim ~/.bash_profile
# 2. 文件内新增一行
export HOMEBREW_NO_AUTO_UPDATE=true
# 3. 重新加载配置文件
source ~/.bash_profile
二、替换brew源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
brew update
# 备用地址-1
cd "$(brew --repo)"
git remote set-url origin https://git.coding.net/homebrew/homebrew.git
brew update
# 备用地址-2
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew-core.git
brew update
PS:官方默认信息
# 1. 重置brew.git
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
# 2. 重置homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
阿里云镜像
1. 替换brew.git 仓库地址:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
还原
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
2. 替换homebrew-core.git 仓库地址:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
还原
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
3. 替换homebrew-bottles 访问地址
这个步骤跟你的 macOS 系统使用的 shell 版本有关系,先来查看当前使用的 shell 版本
echo $SHELL
/bin/zsh
3.1 zsh替换成阿里巴巴的 homebrew-bottles 访问地址:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
还原
vi ~/.zshrc
# 然后,删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置
source ~/.zshrc
3.2 bash替换成阿里巴巴的 homebrew-bottles 访问地址:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
还原
vi ~/.bash_profile
# 然后,删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置
source ~/.bash_profile
Homebrew 更新命令
https://www.onlyling.com/archives/509
更新 Homebrew 自己
brew update
查看哪些安装包需要更新
brew outdated
更新安装包
brew upgrade # 更新所有的包
brew upgrade $FORMULA # 更新指定的包
清理旧版本
brew cleanup # 清理所有包的旧版本
brew cleanup $FORMULA # 清理指定包的旧版本
brew cleanup -n # 查看可清理的旧版本包,不执行实际操作
锁定不想更新的包
brew pin $FORMULA # 锁定某个包
brew unpin $FORMULA # 取消锁定
查看安装包的相关信息
brew info $FORMULA # 显示某个包的信息
brew info # 显示安装了包数量,文件数量,和总占用空间
brew deps --installed --tree # 查看已安装的包的依赖,树形显示
其他
列出已安装包
brew list
删除
brew rm $FORMULA # 删除某个包
brew uninstall --force $FORMULA # 删除所有版本