Homebrew installation tutorial on M1 chip Mac

At present, Homebrew has not completed the adaptation of Mac models equipped with Apple Silicon CPU, and the installation tutorial is quite chaotic. I had a scuffle with Du Niang for an hour, and then found a baby blog, which is roughly as follows:

Article link: Homebrew installation tutorial on M1 chip Mac - Zhihu

Install ARM Homebrew

The ARM version of Homebrew needs to be installed in the / opt/homebrew path. In the early days, it was necessary to manually create a directory and execute commands. At present, the latest script does not need manual operation.

Direct execution:

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

Then you need to set environment variables. The specific operation steps are as follows. You must read them carefully.

PS: terminal type: the result displayed according to the execution command echo $SHELL:

  • /bin/bash => bash => .bash_profile
  • /bin/zsh => zsh => .zprofile

If you encounter the problem of invalid environment variables, it is recommended to go back to check the terminal type and make the correct settings.

Starting with Mac OS Catalina (10.15. X), MAC uses zsh as the default Shell and uses zprofile, so the corresponding command:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

If it is macOS Mojave # or lower and has not configured zsh by itself, use it bash_profile:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

Extended reading: Use zsh as default Shell on Mac

Install X86 Homebrew

Because many software packages do not support ARM architecture, we can also consider using x86 Homebrew.

Add arch - X86 before the command_ 64, you can execute the command in X86 mode, for example:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

Multi version coexistence

If you have both ARM and X86 installed, you need to set an alias to distinguish commands.

The same is true zprofile or bash_ Add in profile:

As for which document to operate, please refer to the previous description of terminal type. If there are similar words below, keep the same operation.

alias abrew='arch -arm64 /opt/homebrew/bin/brew'
alias ibrew='arch -x86_64 /usr/local/bin/brew'

abrew and ibrew can be customized according to your preferences.

Then execute ~ /. Source Zprofile or source ~ / bash_ The profile command updates the file.

Set mirror

Note: the installation script in this article will set the source image of China University of science and technology. If you also want to set the image of cask and bottles, please select the execution code according to the comments below.

For more detailed tutorials, please refer to the previous "Homebrew installation tutorial under mac"

During execution, modify the brew in the "$(brew --repo)" code according to the actual situation.

If you only use one version of Homebrew, just execute the command directly. If you want multiple versions to coexist or use aliases, replace the brew keyword with the alias name, such as abrew and ibrew in front.

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

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

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

# Pots for Zsh and 1 out of 2 below
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile

# bottles for bash and 1 out of 2 above
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile

Tags: Mac iOS brew MacBook m1

Posted by sp@rky13 on Mon, 18 Apr 2022 13:48:27 +0930