网页显示代码,如下图所示;

- 将该网页保存为homebrew_install.rb文件,放在某一文件夹内
更改脚本中的资源链接,替换成清华大学的镜像
- 把这句屏蔽掉
BREW_REPO = "https://github.com/Homebrew/brew".freeze
- 加上这两句
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
CORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze
- 进入到homebrew_install.rb文件目录内,执行以下命令(记得进入文件目录下,才能找到文件哦)
ruby homebrew_install.rb
如果出现如下错误
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-11.3
Software Update Tool
Downloading Command Line Tools for Xcode
Error downloading Command Line Tools for Xcode: The operation couldn’t be completed. (PKDownloadError error 8.)
Done.
Error downloading updates.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
在App Store 手动下载Xcode即可
- 出现如下错误:
'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': Failed to connect to github.com port 443: Operation timed out
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
原因是因为源不通,代码下载不下来,解决方法就是更换国内镜像源:
执行下面这句命令,更换为中国科学技术大学的镜像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
- 在执行如下语句,安装成功
ruby homebrew_install.rb
- 然后把homebrew-core的镜像地址也设为中国科学技术大学的国内镜像
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
- 执行更新:
brew update
- 最后用这个命令检查无错误,这样海外和已经有系统全局代理设置的朋友们就可以直接使用 brew 命令安装软件了。
brew doctor
更换源:
直接使用 Homebrew 还需要更改默认源,以下是将默认源替换为国内 USTC 源的方法。(如不更换源下载为龟速)
- 替换核心软件仓库
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
- 替换 cask 软件仓库(提供 macOS 应用和大型二进制文件)
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
- 替换 Bottles 源(Homebrew 预编译二进制软件包)
bash(默认 shell)用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
zsh 用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
- 基本用法操作命令:
假定操作对象为 wget,请替换为自己需要的软件包名
更新 Homebrew brew update
更新所有安装过的软件包 brew upgrade
更新指定的软件包 brew upgrade wget
查找软件包 brew search wget
安装软件包 brew install wget
卸载软件包 brew remove wget
列出已安装的软件包 brew list
查看软件包信息 brew info wget
列出软件包的依赖关系 brew deps wget
列出可以更新的软件包 brew outdated
网友评论