Homebrew是一款包管理工具,目前支持macOS和linux系统。主要有四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles
官方脚本安装
\
url: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out
官方脚本无法使用的原因是raw.githubusercontent.com
访问很不稳定,也可以采用写入hosts
的方式,可以一定程度解决GitHub
资源无法访问的问题.
- 试着先在终端
ping github.com
MacBook-Pro:~$ping github.com
PING github.com (192.30.252.131): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
- 如果 ping 出来是这种结果
-
- 在终端中
sudo vi /etc/hosts打开编辑文件 - 下面添加
192.30.253.113(上面ping出来的ip)github.com
- 在终端中
-
- 保存退出
- 在终端
ping github.com
- 如果ping出来是这样了,重新执行官方命令
换镜像源安装
如果想换镜像源,推荐使用镜像助手获取执行脚本
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
如果命令执行中卡在下面信息
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
Control + C中断脚本执行如下命令:
- 克隆Homebrew-core
cd "$(brew --repo)/Library/Taps/homebrew/
mkdir homebrew-core
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
- 克隆Homebrew-cask
cd "$(brew --repo)/Library/Taps/homebrew/"
mkdir homebrew-cask
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
\
设置镜像
中科大源
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
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
brew update
bottles镜像
镜像以中科大源为例。
从macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认Shell,对应文件是.zprofile,所以命令为:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile
如果是macOS Mojave 及更低版本,并且没有自己配置过zsh,对应文件则是.bash_profile:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile
注意:上述区别仅仅是.zprofile
和.bash_profile
不同,文章如有再次提及编辑.zprofile
,均按此方法替换。如果想使用清华源:
把
https://mirrors.ustc.edu.cn/homebrew-bottles/bottles
替换为
https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles
恢复默认源
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
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
homebrew-bottles配置只能手动删除,将 ~/.zprofile 文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com内容删除,并执行 source ~/.zprofile。
brew常用命令
显示帮助
brew –help
安装软件
brew install --cask 软件名
卸载软件
brew uninstall 软件名
搜索软件
brew search 软件名
查看经安装软件列表
brew list
更新所有软件
brew update
更新某具体软件
brew upgrade git
显示软件内容信息
brew info git
查看哪些已安装的程序需要更新
brew outdated
\
\