Correct posture for installing Homebrew on Mac

Posted by mdub2112 on Fri, 14 Jan 2022 11:49:48 +0100

Transferred from: Qiao Yizhen
Address: https://www.cnblogs.com/joyce33/p/13376752.html
Thank the author for his hard work, respect copyright and start with me.

Nothing is difficult in the world, as long as you find the correct installation method of Homebrew.

What is Homebrew

Homebrew is the package manager of mac. You can download and install the required software packages by executing the corresponding commands. You can save yourself the tedious steps of downloading, decompressing, dragging (installing). For example, to install the server nginx, open the terminal and execute the following commands:

brew install nginx

Homebrew official documentation https://brew.sh/

How to install Homebrew

Method 1: install script on brew official website

Execute command:

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

At this time, there is likely to be a problem: either download extremely fast, or directly appear the following prompt

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

Reason: This is http://raw.githubusercontent.com Caused by unstable access.

At this time, it is necessary to change a scientific and efficient installation method, namely method 2.

Method 2: brew image installation script (the fastest and most effective personal test)

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

The script uses the image of China University of science and technology to accelerate access, and only modifies the warehouse address, which will not cause security risks. About Homebrew image service provided by China University of science and technology https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git

Note: pay attention to the speed here. A few hundred kib/s or a few m/s is normal. If there are only a few kib/s, it is usually an invalid installation method. Generally, an error will be reported after loading dozens of percent.

 

How to avoid pits during Homebrew installation

1. In case of Error: Checksum mismatch

Error codes are as follows:

curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Checksum mismatch.
Expected: b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86
Actual: e8a348fe5d5c2b966bab84052062f0317944122dea5fdfdc84ac6d0bd513c137
Archive: /Users/joyce/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
To retry an incomplete download, remove the file above.
Error: Failed to install Homebrew Portable Ruby (and your system version is too old)!
Failed during: /usr/local/bin/brew update --force

Here is portable-ruby-2.6.3 under the Homebrew directory_ 2.yosemite. bottle. tar. For the installation interruption caused by GZ file, just go to the corresponding path above, delete this file and re execute the installation command:

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

2. If you get stuck in Cloning into

 

It can be concluded from the turtle speed here that it is stuck. Immediately interrupt the script with Control + C, and then execute the following command:

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

After execution, you can see:

 

The speed is so fast that it can be installed at once.

Note: Installation successful appears at the end! Or Checking out files: 100% (5392/5392), done Indicates that the installation was successful.

Why do I need to configure Homebrew after installation

As mentioned earlier, Homebrew is usually used to download software, but it is very slow to install software. In order to improve the installation speed, you need to change the installation source of Homebrew and replace it with a domestic image.

The Homebrew image managed and maintained by China University of science and technology is used here. The first two items must be configured, and the last two items can be configured as required.

1. Required settings

  • Replace brew git:

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

  • Replace homebrew core git:

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

2. Set as required

  • Replace homebrew cask git:

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

  • Replace homebrew pots:

First, distinguish which terminal tool your mac uses. If it is bash, execute:

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

If zsh, execute:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

Note: Homebrew is mainly composed of four parts: brew, Homebrew core, Homebrew cask and Homebrew bottles. Their corresponding functions are as follows:

formfunction
HomebrewSource code warehouse
homebrew-coreHomebrew core source
homebrew-caskProvides installation of macos applications and large binary files
homebrew-bottlesPrecompiled binary package

What are the basic uses of Homebrew

// Query:
brew search Software name

// Installation:
brew install Software name

// Uninstall:
brew uninstall Software name

// Update Homebrew:
brew update 

// To view Homebrew configuration information:
brew config 

Note: if you use the official script, you will also encounter the problem that the uninstall address cannot be accessed. You can replace it with the following script:

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"

Reference articles

Installing Homebrew under mac

Homebrew source of HKUST



Author: a dream seeking teenager
Link: https://www.jianshu.com/p/e0471aa6672d
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, and for non-commercial reprint, please indicate the source.