Homebrew 是 Mac 的包管理器,類似於 Linux 中的 apt,Windows 中的 choco。
自從 M1 芯片發布,Homebrew 正在積極適配新架構,如今已經有了原生支持 ARM 架構的 ARM 版本 Homebrew。
需要注意的是,ARM 版本的 Homebrew 安裝在 /opt/homebrew
路徑下,而非 x86 版的 /usr/local/Homebrew
。
不過對於一些沒有適配新架構的軟件包,可能仍需要安裝 x86 版本的 Homebrew。
安裝 ARM 版 Homebrew
可直接執行官方安裝腳本:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
如果安裝順利,那恭喜你,你將會看到:
==> 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
接下來只要執行日志中下一步的腳本即可:
$ echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xiamu/.zprofile
$ eval "$(/opt/homebrew/bin/brew shellenv)"
查看 Homebrew 版本:
$ brew -v
Homebrew 3.3.11
Homebrew/homebrew-core (git revision 7685d63742b; last commit 2022-01-22)
至此結束。
常見問題
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
類似上述報錯,基本屬於是網絡問題,有多個可嘗試解決方案。
方案一
遇到這類問題最常用的就是更改 hosts 文件了,步驟如下:
- 打開 https://ipaddress.com/website/raw.githubusercontent.com ;
- 將其中查詢到的 ip 復制出來;
- 在終端執行
sudo vim /etc/hosts
,輸入密碼; - 在hosts文件中添加一行
<復制的ip地址> raw.githubusercontent.com
; - 重新執行安裝腳本。
方案二
以上方案一不一定每次都管用,比如我這次(淚目
如果你有梯子,可以嘗試開啟全局代理執行安裝腳本,或者直接下載安裝腳本文件本地執行。
方案三
如果你沒有梯子,可以使用 Homebrew 國內源,具體教程 看這里。
方案四
如果你跟我一樣是個強迫症,覺得國內源不干凈可能更新不及時,也不想手動下載腳本,一定要使用官方推薦方式,但是全局代理又行不通,可以嘗試讓終端使用代理:
首先確定本機代理監聽的協議及端口,如:socks5://127.0.0.1:1086
。
在終端測試下代理:
$ all_proxy="socks5://127.0.0.1:1086" curl https://ip.cn/api/index\?ip\=\&type\=0
{"rs":1,"code":0,"address":"美國 加利福尼亞 ","ip":"65.49.204.191","isDomain":0}%
可以看到請求是成功走代理的,對比不走代理:
$ curl https://ip.cn/api/index\?ip\=\&type\=0
{"rs":1,"code":0,"address":"中國 浙江省 杭州市 移動","ip":"xx.xx.xx.xx","isDomain":0}%
接下來就簡單了,直接在安裝腳本添加 all_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)"
安裝 x86 版 Homebrew
安裝 x86 版 Homebrew 及處理 兩個版本的共存問題請參考參考鏈接。
參考:
在 M1 芯片 Mac 上使用 Homebrew https://sspai.com/post/63935