首先安装Command_Line_Tools_for_Xcode

下载地址

1
https://developer.apple.com/download/more/

终端输入命令安装homebrew,需要输入电脑密码

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

镜像选择

image-20221022151825549

开始安装

image-20221022151918255

安装完成后出现报错信息

image-20221022153709967

修改环境变量

利用命令进入macOS系统的根目录

1
cd ~

打开.zshrc文件

1
$ open -e .zshrc

修改路径

1
2
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"

image-20221022154059485

image-20221022154203401

存修改,读取文件中环境变量路径,使其生效

1
source .zshrc

查看homebrew是否安装成功

image-20221022155223254

复制执行两两条命令

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

安装成功

image-20221022160446246

安装git

1
brew install git

image-20221022161238762

查看git版本

1
git --version

image-20221022161326251