The correct posture of installing Homebrew on Mac

What is Homebrew?

Homebrew is a package manager for mac. You only need to execute the corresponding command to download and install the required software package, which can save you from downloading, decompressing, dragging (installing) and other cumbersome steps. For example, to install server nginx, open the terminal and execute the following command to install:

brew install nginx

copy

Homebrew official documentation https://brew.sh/

How to install Homebrew

Method 1: The installation script of brew official website

Excuting an order:

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

copy

At this time, there may be a problem: either the download speed is extremely slow, or the following prompt will appear directly

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

copy

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

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

Method 2: brew image installation script (pro-test is the fastest and most effective)

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

copy

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

Note: Pay attention to the speed here, hundreds of kib/s or several m/s are normal. If there are only a few kib/s, it is usually an invalid installation method, and an error will be reported after loading tens of percent.

How to avoid pitfalls when installing Homebrew

1. If Error: Checksum mismatch appears.

The error code is 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

copy

Here is the installation interruption caused by the portable-ruby-2.6.3_2.yosemite.bottle.tar.gz file in the Homebrew directory. You only need to go to the corresponding path above, delete this file, and execute the installation command again:

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

copy

2. If stuck in Cloning into...

Judging by the slow speed here, it can be concluded that it is stuck, immediately use Control + C to interrupt the script, 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

copy

After execution, you can see:

The speed is so fast that it flies up immediately, and it can be installed in one go.

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

Why does Homebrew need to be configured after installation

As mentioned earlier, Homebrew is usually used to download software, but it is very slow when installing software. In order to improve the installation speed, it is necessary to change the installation source of Homebrew and replace it with a domestic mirror.

The Homebrew image hosted and maintained by the University of Science and Technology of China is used here. Among them, the first two items must be configured, and the latter two items can be configured on demand.

1. Required settings

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

copy

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

copy

2. Set as needed

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

copy

  • Replace homebrew-bottles:

First of all, you must 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

copy

If it is zsh, execute:

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

copy

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

composition

Function

Homebrew

source code repository

homebrew-core

Homebrew core sources

homebrew-cask

Provides installation of macos apps and large binaries

homebrew-bottles

precompiled binary packages

What are the basic usage of Homebrew

// 查询:
brew search 软件名

// 安装:
brew install 软件名

// 卸载:
brew uninstall 软件名

// 更新 Homebrew:
brew update 

// 查看 Homebrew 配置信息:
brew config 

copy

Note: Using the official script will also encounter the problem that the uninstall address cannot be accessed, which can be replaced with the following script:

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

copy

reference article

Quickly install Homebrew tutorial on mirroring under mac

HKUST Homebrew source

write at the end

I have tried several installation methods before this, such as downloading a brew_install.rb file, and then executing the command ruby ​​brew_install.rb. It worked at the beginning, but an error will be reported in the middle of the download, and the error method is different. I also tried several corresponding solutions, but they all died in the end. Only this mirror installation can be successful, and the download speed is very fast.

Guess you like

Origin blog.csdn.net/weixin_38860565/article/details/128088657