MacOs M1安装Homebrew 在国内最简单方法

前言

之前写过一篇在intel芯片的Mac上安装Homebrew的文章,现在更换了M1芯片的Mac后,发现以前的方法用不了。经过查阅,最后安装成功后,整理出这篇文章。

旧文章:macOS安装Homebrew太慢,换用清华镜像

当前文章也基本适用intel芯片的Mac

安装

开源安装脚本库:https://gitee.com/cunkai/HomebrewCN

复制以下内容到你的终端:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

回车运行,按照提示运行下去就可以了

错误

做完上面的傻瓜式操作,理论上就OK了,但是我这边出现了安装完后用不了的错误

command not found : brew

经过检查后发现,是因为M1芯片的包安装位置不在是以前的/usr/local/
而是/opt/homebrew,所以要将配置文件里的环境变量改过来
1、首先进入根目录

$ cd ~

2、创建.zshrc文件

$ touch .zshrc

3、打开文件进行编辑

$ open -e .zshrc

4、如果有旧的环境就修改,没有就新增

export PATH=/opt/homebrew/bin:$PATH
export PATH=/opt/homebrew/sbin:$PATH

5、保存
使用 command + s
6、生效环境变量

$ source .zshrc

7、测试

$ brew -v

Git错误

执行brew install时出现报错:

fatal: not in a git directory
Error: Command failed with exit 128: git

1、执行brew -v检查是否有错误信息:

Homebrew 4.0.23-12-ge986264
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

2、根据提示复制内容在终端中执行即可:

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask

完事

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐