文章声明:此文基于木子实操撰写
生产环境:MacOS 10.15.5 (19F96)
论证耗时:1h
撰文耗时:1h
校文耗时:30m
问题关键字:Homebrew,brew,brew install
Homebrew包管理简介
Homebrew是一个很方便的包管理器,主要用于MacOS包管理,目前也支持Linux包管理。Homebrew通过tap方式定义源,官方默认提供了brew、homebrew-core 、homebrew-cask 、homebrew-bottles四个常用的源(仓库),用户也可以通过tap定义自己的源。
在使用brew install
安装软件的过程中,经常会遇到安装缓慢、卡死的情况,这大多是由于Homebrew的默认安装源位于国外,国内访问速度慢造成的,解决这个问题的方法是将安装源替换为国内镜像,常用的国内镜像包括:阿里云镜像、清华镜像、中科大镜像等。
阿里云镜像:https://mirrors.aliyun.com
清华镜像:https://mirrors.tuna.tsinghua.edu.cn
中科大镜像:https://mirrors.ustc.edu.cn
本文撰写的目的是简单的介绍四个常用的源,以及如何更换为国内镜像实现快速安装软件。
brew:Homebrew源代码仓库。
默认地址:https://github.com/Homebrew/brew.git
homebrew-core:Homebrew核心源(仓库),它是brew install的默认安装源(仓库)。
默认地址:https://github.com/Homebrew/homebrew-core.git
homebrew-cask:homebrew-cask源(仓库),提供macOS应用和大型二进制文件的安装。通常我们在mac操作系统上安装图形用户界面软件,系统都会提示“若要安装,请拖动此图标…”。homebrew-cask扩展了Homebrew,为安装和管理Atom和Google Chrome之类的图形用户界面应用程序带来了优雅、简单和速度。
默认地址:https://github.com/Homebrew/homebrew-cask.git
homebrew-bottles:Homebrew预编译二进制软件包。
默认地址:https://bintray.com/homebrew/bottles
安装Homebrew
下载安装脚本
1
| curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
|
修改安装源
1 2 3 4 5 6 7
| vi brew_install BREW_REPO = "https://github.com/Homebrew/brew".freeze CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
BREW_REPO = "https://mirrors.ustc.edu.cn/git/brew.git".freeze CORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze
|
安装Homebrew
1 2 3 4 5 6 7 8
| /usr/bin/ruby brew_install
==> Tapping homebrew/core Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
git clone https://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
/usr/bin/ruby brew_install
|
更换后续程序包的安装源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/git/homebrew/brew.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/git/homebrew/homebrew-core.git
cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc source ~/.zshrc
~/Documents/Python3-venv » brew config HOMEBREW_VERSION: 2.2.17 ORIGIN: https://mirrors.aliyun.com/homebrew/brew.git HEAD: ca5eac845dc11e991d7d8f8c85aebb82dd454f37 Last commit: 10 days ago Core tap ORIGIN: https://mirrors.aliyun.com/homebrew/homebrew-core.git Core tap HEAD: eaae1b6ba12f49cbf3ef979d2bd2426c9dbb9aef Core tap last commit: 23 hours ago HOMEBREW_PREFIX: /usr/local HOMEBREW_MAKE_JOBS: 8 CPU: octa-core 64-bit kabylake Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby Clang: 11.0 build 1100 Git: 2.21.0 => /Library/Developer/CommandLineTools/usr/bin/git Curl: 7.64.1 => /usr/bin/curl macOS: 10.15.5-x86_64 CLT: 11.0.0.0.1.1567737322 Xcode: N/A
|
brew常用命令
1 2 3 4 5 6 7 8 9
| brew update brew install 包名称 brew uninstall 包名称 brew search 包名称 brew upgrade 包名称 brew info 包名称 brew outdated brew cleanup 包名称 brew list
|
还原源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| 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
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
source ~/.bash_profile source ~/.zshrc
|
参考链接
https://mirror.tuna.tsinghua.edu.cn/help/homebrew/
https://mirrors.aliyun.com/homebrew/