Mac 安装homebrew Mac安装Git

文章目录

  • 1 homebrew介绍
  • 2 下载Brew
    • 2.1 使用中文镜像进行安装
  • 3 配置brew环境变量
  • 4 更换镜像源
  • 5 安装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 "[email protected]"

参考

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

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

你可能感兴趣的:(Windows,Linux,WSL,macos,git,linux)