【原创】MacOS 配置 Homebrew 国内源

简介

环境信息

MacOS 10.15.6
homebrew 2.5.1

正文

1、设置 git remote

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

设置 homebrew core,下面命令将设置 homebrew core 的 REPO 地址为清华源

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

设置 homebrew cask,下面命令将设置 homebrew core 的 REPO 地址为清华源

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

设置 homebrew cask-fonts,下面命令将设置 homebrew cask-fonts 的 REPO 地址为清华源

git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git

设置 homebrew cask-drivers,下面命令将设置 homebrew cask-drivers 的 REPO 地址为清华源

git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

注:

(1) 上面的命令不需要全部执行,请根据你的需要设置即可。比如,你只用到了 homebrew 的基本命令,并没有用到 brew cask 相关的功能。那么后面的三项设置均可以不用设置。

(2) 如果执行上面的命令提示没有目录,可以自行创建,如下如示:

$ mkdir -p "$(brew --repo homebrew/cask-fonts)"
$ mkdir -p "$(brew --repo homebrew/cask-drivers)"

2、更新 brew

brew update

示例:

$ brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
remote: Counting objects: 11034, done.
remote: Compressing objects: 100% (5218/5218), done.
remote: Total 11034 (delta 6935), reused 9050 (delta 5814)
Receiving objects: 100% (11034/11034), 3.71 MiB | 2.53 MiB/s, done.
Resolving deltas: 100% (6935/6935), done.
From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask
   9b065dbdc8..327e8ca374  master     -> origin/master
remote: Counting objects: 25994, done.
remote: Compressing objects: 100% (7462/7462), done.
remote: Counting objects: 10917, done.
remote: Compressing objects: 100% (5157/5157), done.
remote: Total 10917 (delta 6848), reused 8963 (delta 5758)
Receiving objects: 100% (10917/10917), 3.88 MiB | 2.56 MiB/s, done.
Resolving deltas: 100% (6848/6848), done.1 MiB | 365.00 KiB/s
From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask
   9b065dbdc8..327e8ca374  master     -> origin/master
remote: Total 25994 (delta 20110), reused 24341 (delta 18528)
Receiving objects: 100% (25994/25994), 6.38 MiB | 1.18 MiB/s, done.
Resolving deltas: 100% (20110/20110), completed with 1727 local objects.
From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core
   096ba9017..b6ca50b6e  master     -> origin/master
Updating /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.
#
Updating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
First, rewinding head to replay your work on top of it...
Fast-forwarded master to origin/master.

总结

1、执行如下命令进行校验

git -C "$(brew --repo homebrew/core)" remote get-url origin

示例:

$ git -C "$(brew --repo homebrew/core)" remote get-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask-drivers)" remote get-url

2、brew 常用命令

以下是我常用到的 brew 相关的命令,不是全部命令,完整的命令可参考 man brew 文档。

brew --help                   # 列举 brew 的帮助信息,常用命令
brew --version                # 查看 brew 版本信息,包含 homebrew, homebrew-core, homebrew-cask
brew update                   # 更新 homebrew, homebrew-core, homebrew-cask 等等的版本
brew doctor                   # 检测 brew 当前环境中的问题
brew search keyword           #  搜索 brew 仓库中包含 keyword 相关的包,如 brew search mysql
brew info package-name        # 获取一个 brew 中存在的包的信息,包括版本,文件大小,下载地址,使用方法等信息。
brew install package-name     # 使用 brew 安装一个包,比如 brew install mysql
brew uninstall package-name   # 使用 brew 卸载一个已安装的包,比如 brew uninstall mysql
brew upgrade package-name     # 使用 brew 更新一个已安装的包,比如 brew upgrade mysql
brew list                     # 列举 brew 安装的包的名称
brew list --cask              # 查看使用 cask 安装的包,brew cask list 命令已经过时了

附录

参考:

https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注