Homebrew is a package management tool currently available for macOS and Linux. There are four main parts: BREW, Homebrew-core, Homebrew-Cask and Homebrew-bottles.

The name of the instructions
brew Homebrew source code repository
homebrew-core Homebrew core source
homebrew-cask Provides installation of macOS applications and large binaries
homebrew-bottles Precompile binary software packages

This article focuses on Homebrew installation and how to speed up access, along with the necessary knowledge.

The source code used in this article is hosted on GitHub and accelerated with Jsdelivr.

homebrew-install

If you are installing Homebrew on a Mac with an M1 chip, read this article first:

Homebrew installation tutorial on M1 Chip Mac

This tutorial has its own home page for a better reading experience, so check it out.

1. Script description

Homebrew default installation script:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Copy the code

If you wait for a while and get the following message, you cannot access the official script address:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out
Copy the code

Follow the following installation instructions.

Official script is not able to use raw.githubusercontent.com is the cause of access is not very stable, I provided above scheme is adopted in the jsdelivr CDN to accelerate access.

In addition, the method of writing hosts can also be adopted to solve the problem that GitHub resources cannot be accessed to some extent. I have also written an operation article, which can be read if necessary.

GitHub Access acceleration Guide

2. Installation instructions

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
Copy the code

If the following information is stuck in the command execution (if the prompt is different, please feedback to me) :

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
Copy the code

Control + C interrupt the script to execute the following command:

cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
Copy the code

caskThere are also problems where the installation fails or gets stuck, and the solution is the same:

cd "$(brew --repo)/Library/Taps/"
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
Copy the code

Continue with the previous installation command after successful execution:

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
Copy the code

==> Installation successful! The installation is successful.

Last update:

brew update
Copy the code

3. Set the mirror

Brew, Homebrew /core are essential projects, Homebrew/CasK, Homebrew /bottles are set according to demand.

You can run the brew config command to view the configuration information.

3.1 Source of UNIVERSITY of Science and Technology

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
Copy the code

3.2 Source from Tsinghua University

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
Copy the code

3.3 Set up bottles

Setting environment variables requires attention to the terminal Shell type, as shown below:

Mirror to the source of science and technology as an example.

Since macOS Catalina(10.15.x), the Mac uses ZSH as the default Shell. The corresponding file is.zprofile, so the command is:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/' >> ~/.zprofile
source ~/.zprofile
Copy the code

If it is macOS Mojave or later and ZSH is not configured, the corresponding file is.bash_profile:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/' >> ~/.bash_profile
source ~/.bash_profile
Copy the code

Note: the above difference is only between.zprofile and.bash_profile. If the article mentions editing.zprofile again, replace it with this method.

If you want to use Tsinghua Source:

The replaced by https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/ https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/Copy the code

At this point, the installation and setup operations are complete.

3.4 Restoring the Default Source

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
Copy the code

The configuration of Homebrew_bottles can only be manually deleted, the content of HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com in ~/. Zprofile file is deleted, and the source ~/.zprofile is executed.

4. Other relevant

4.1 cask

Cask currently reads software from GitHub, and GitHub Api has limited access. If cask is used frequently, you can apply for an Api Token and configure it to HOMEBREW_GITHUB_API_TOKEN in the environment variable.

Append to.zprofile, replacing yourtoken:

echo 'export HOMEBREW_GITHUB_API_TOKEN=yourtoken' >> ~/.zprofile
source ~/.zprofile
Copy the code

Note: Because Cask downloads software from GitHub, it is currently not accelerated.

4.2 How Do I Uninstall Homebrew

The uninstall address cannot be accessed using the official script. Use the following script:

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"
Copy the code

4.3 Feedback Problems

  • Wechat Group (recommended)
  • GitHub Issue
  • comments

5. To summarize

In the previous process we pointed the brew and Homebrew-core addresses to the USTC mirror.

You can modify the install.sh script to preset the image address.

  STAT="stat --printf"
  CHOWN="/bin/chown"
  CHGRP="/bin/chgrp"
  GROUP="$(id -gn)"
  TOUCH="/bin/touch"
fi
# Replace BREW_REPO here
BREW_REPO="https://mirrors.ustc.edu.cn/brew.git"
Copy the code

If it helps you

Like, share, collect, can let more people can find the article, this is also to my recognition and encouragement, thank you.

Refer to the article

  • Tsinghua University open source software mirror station
  • USTC source

📣 AD break

GitMaster presents git project code as a tree.

  • 🚀 Code tree supportGitHub,GitLab,Gitee
  • 🖊️ Supports private deployment pages with one-click markup
  • 🗂️ Visualization of file submission historygit history
  • 🔔 GitHubNotification and reminder function
  • ⬇ ️ supportGitHubDownload files and directories

The installation

The shop installed

  • Chrome Web Store
  • Edge Web Store

FAQ

Most of the problems are due to resource instability, accelerated by agents if possible.

Proxy use can refer to the following article:

  • Mac terminals use SSR proxies
  • How do I make macOS “terminals” proxy?

fatal: unable to access xxx

HEAD is now at 028e733e7 Merge pull request #10260 from reitermarkus/audit-livecheck fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': transfer closed with outstanding read data remaining fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...]  -- [<file>...] 'Copy the code

Solution:

  • According to the articleThe GitHub page githubuserContent address cannot be accessedTo givegithub.comThe domain name to accelerate
  • Access by proxy

Set image invalid, installation is still slow

By slow installation, I mean brew itself is slow to install (the image address was not set successfully).

You can run the echo $SHELL command to check the terminal type.

  • bash: /bin/bash
  • zsh: /bin/zsh

Then set the mirror based on the terminal type. For details, see “Setting a Mirror”.

command not found: brew

Generally, the environment variable is invalid. Please use echo $SHELL to confirm the terminal type. Refer to the previous section.

/opt/homebrew/bin = /opt/homebrew/bin = /opt/homebrew/bin

zsh

echo export PATH=/opt/homebrew/bin:$PATH> > ~ /. Zprofilesource ~/.zprofile
Copy the code

bash

echo export PATH=/opt/homebrew/bin:$PATH> > ~ /. Followingsource ~/.bash_profile
Copy the code

Otherwise, /usr/local/bin may need to be manually added to the environment variable because of special circumstances:

zsh

echo export PATH=/usr/local/bin:$PATH> > ~ /. Zprofilesource ~/.zprofile
Copy the code

bash

echo export PATH=/usr/local/bin:$PATH> > ~ /. Followingsource ~/.bash_profile
Copy the code

SHA256 mismatch

Error: An exception occurred within a child process: ChecksumMismatchError: SHA256 mismatch Expected: 01059532335fefc5e0e7a23cc79eeb1dc6fea477606981b89f259aa0e0f9abc1 Actual: 641ba394c891cee16dfa45873906edab12edfc9befaa121649bb18e7b7d574bf Archive: /Users/XXX/Library/Caches/Homebrew/downloads/1124b500fc261f6d9be6193eca8c120f4dfb7ecd3470ac7d8edc1d04ecc5b345--jdk13u-jd K-13.0.2 +8.tar. bZ2 To retry an incomplete download, remove the file above.Copy the code

Please try the solution when the problems: blog.csdn.net/lemostic/ar…


Follow the public account: Lake Sword to find out more about me.