Mac m1 Install Homebrew

Posted by XeNoMoRpH1030 on Mon, 24 Jan 2022 06:13:11 +0100

Homebrew is the package manager for Mac, similar to apt on Linux and choco on Windows.

Since the M1 chip was released, Homebrew is actively adapting to the new architecture and now has an ARM version of Homebrew that natively supports the ARM architecture.

Unlike x86, the ARM version of Homebrew must be installed in the / opt/homebrew path, not in the previous / usr/local/Homebrew.

However, for some packages that do not adapt to the new architecture, you may still need to install the x86 version of Homebrew.

Install ARM version of Homebrew

The official installation script can be executed directly:

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

If the installation is successful, congratulations, and you will see:

==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xiamu/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

Next, simply execute the next script in the log:

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

View the Homebrew version:

$ brew -v
Homebrew 3.3.11
Homebrew/homebrew-core (git revision 7685d63742b; last commit 2022-01-22)

This concludes.

Common problem

  • curl: (35) LibreSSL SSL_connect: Connection reset by peer in connection to raw.githubusercontent.com:443
  • curl: (28) Failed to connect to raw.githubusercontent.com port 443: Operation timed out

Similar to the above errors, the basic problem is network problems, there are several solutions to try.

Scheme One

The most common way to encounter this type of problem is to change the hosts file, as follows:

  1. open https://ipaddress.com/website/raw.githubusercontent.com
  2. Copy the ip queried in it;
  3. Execute sudo vim/etc/hosts at the terminal, enter the password;
  4. Add a line <copied ip address> raw to the hosts file. Githubusercontent. Com;
  5. Reexecute the installation script.

Option 2

The above solutions may not work every time, for example, this time (tears)

If you have a ladder, you can try opening the global agent to execute the installation script or download the installation script file to execute locally.

Option 3

If you don't have a ladder, you can use Homebrew Source, a specific tutorial Look here.

Option IV

If you are an obsessive-compulsive disorder like me, feel dirty domestic sources may not update in time, and do not want to download scripts manually, be sure to use the official recommendation, but the global agent does not work, you can try to let the terminal use the agent:

First, determine the protocol and port that the local agent listens on, such as socks5://127.0.0.1:1086.

Under Terminal Test Proxy:

$ all_proxy="socks5://127.0.0.1:1086" curl https://ip.cn/api/index\?ip\=\&type\=0
{"rs":1,"code":0,"address":"California, USA  ","ip":"65.49.204.191","isDomain":0}% 

You can see that the request was successfully proxied, compared with no proxy:

$ curl https://ip.cn/api/index\?ip\=\&type\=0
{"rs":1,"code":0,"address":"Hangzhou Mobile, Zhejiang Province, China","ip":"xx.xx.xx.xx","isDomain":0}%

Now it's easy to add all_directly to the installation script Proxy="socks5://127.0.0.1:1086":

$ /bin/bash -c "$(all_proxy="socks5://127.0.0.1:1086" curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install x86 Homebrew

Refer to the reference link for installing the x86 version of Homebrew and dealing with the coexistence of the two versions.

Reference resources:

Using Homebrew on the Mac on the M1 chip https://sspai.com/post/63935

Topics: Mac terminal