Mac 安装homebrew Mac安装Git

1 homebrew介绍

Homebrew是一款包管理工具,目前支持macOS和Linux系统
主要有四个部分组成:

  • brew
  • homebrew-core
  • homebrew-cask
  • homebrew-bottles

2 下载Brew

官方:https://brew.sh/

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

输入密码进行安装

2.1 使用中文镜像进行安装

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

输入相关的源进行安装
安装成功之后执行 source /Users/name/.zprofile 或者重启后生效

配置git仓库

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

3 配置brew环境变量

在安装完成后如果遇到command not found: brew的错误,一般是环境变量无效
macOS Catalina(10.15.x) 版开始,Mac使用/bin/zsh作为默认Shell,其对应的配置文件为~/.zshrc

M1芯片ARM版Homebrew最终会被安装在/opt/homebrew路径下,而之前Intel芯片的Mac则会被安装到/usr/local/Homebrew路径下

使用uanme -m 来查看CPU型号

对不同型号不同版本的进行配置:

M1芯片:
zsh MacOS10以后的版本

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

bash MacOS10之前的版本

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

4 更换镜像源

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

brew update

M1 chip

# zsh
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile

5 安装Git

# 搜索git
brew search git

# 安装git
brew install git

# 更新git
brew upgrade git

# 卸载git
brew uninstall git

配置git

git config --global user.name "rocky"
git config --global user.email "3xxxxx5@qq.com"

参考

Mac安装Homebrew_rockvine的博客-CSDN博客https://blog.csdn.net/rockvine/article/details/121895416

踩坑!Macbook pro快速安装homebrew!各种问题解决! https://zhuanlan.zhihu.com/p/542207838

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值