/usr/local/Cellar/foo/0.1
/usr/local/Cellar/foo
/usr/local
)/usr/local/Cellar
/usr/local/Caskroom
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
# 查看 Homebrew 版本
$ brew -v
Homebrew 2.5.8-62-g084f2e7
Homebrew/homebrew-core (git revision d7b6c8; last commit 2020-11-04)
Homebrew/homebrew-cask (git revision 9c073; last commit 2020-11-04)
# 更新 Homebrew
$ brew update
# 查看包安装位置
$ ECHO "$(brew --repo)"
/usr/local/Homebrew
# 查看 Homebrew 帮助信息
$ brew -h
Example usage:
brew search [TEXT|/REGEX/]
brew info [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
Troubleshooting:
brew config
brew doctor
brew install --verbose --debug FORMULA
Contributing:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
Further help:
brew commands
brew help [COMMAND]
man brew
https://docs.brew.sh
# 安装 package
$ brew install <packageName>
# 安装指定版本package;如:安装 12 版本的 node
$ brew install node@12
# 卸载
$ brew uninstall <packageName>
# 查询可用包
$ brew search <packageName>
# 查看已安装包列表
$ brew list
# 查看任意包信息
$ brew info <packageName>
/usr/local/Cellar
下的独立目录,并将文件软链接至 /usr/local/bin
。Homebrew 的文件路径:
/usr/local/Homebrew
下Cellar/包名/版本号/
的形式来安放。为了方便,这里提供一份切换为 中科大源 和切换为原始源 的命令
需要继续修改 bottles镜像,然后update 才生效
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
切换为原始的:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
详细解释
# 1、替换 brew.git
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 也可写为 git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 清华大学 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 中科大:https://mirrors.ustc.edu.cn/brew.git
# 阿里云:https://mirrors.aliyun.com/homebrew/brew.git
# 腾讯云:https://mirrors.cloud.tencent.com/homebrew/brew.git
# 原: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.ustc.edu.cn/homebrew-core.git
# 清华大学 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 中科大:https://mirrors.ustc.edu.cn/homebrew-core.git
# 阿里云:https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 腾讯云:https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git
# 原: https://github.com/Homebrew/homebrew-core.git
# 3、替换homebrew-cask.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 清华 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 中科大: https://mirrors.ustc.edu.cn/homebrew-cask.git
# 原: https://github.com/Homebrew/homebrew-cask.git
从macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认shell,使用的配置文件:~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zprofile
source ~/.zprofile
# 清华大学 https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles'
# 中科大:https://mirrors.ustc.edu.cn/homebrew-bottles
# 腾讯云:https://mirrors.cloud.tencent.com/homebrew-bottles
如果是以前的macOS版本,Mac使用bash作为默认shell,使用的配置文件:~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
如果要把源切换为原来的,也需要注释掉环境变量中的 HOMEBREW_BOTTLE_DOMAIN
然后重开一个 terminal 环境
最后使修改生效,并显示进度
$ brew upgrade --verbose
报错1:
homebrew-core is a shallow clone.
如果执行 brew update 遇到下属情况,一般切换源可以解决
执行报错
$ brew update
Error:
homebrew-core is a shallow clone.
homebrew-cask is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
处理方法
$ git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 5105, done.
remote: Compressing objects: 100% (4904/4904), done.
remote: Total 5105 (delta 44), reused 886 (delta 5)
Receiving objects: 100% (5105/5105), 4.14 MiB | 1.17 MiB/s, done.
Resolving deltas: 100% (44/44), done.
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 测试,获取 url
$ git remote get-url origin
https://mirrors.ustc.edu.cn/brew.git
$ brew update
Already up-to-date.
报错2
Not a valid ref: refs/remotes/origin/master
打开路径 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
, 如果只有一个 .git
文件,也会导致 update 失败,需要重新拉去。
$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
$ git fetch --prune origin
$ git pull --rebase origin master
$ brew update
伊织 2021-11-29