官网安装
按照官网(https://brew.sh/index_zh-cn.html)给的命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
在终端上运行这三个命令将Homebrew添加到你的PATH中:
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/wangtianji/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/wangtianji/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
查看是否安装
wangtianji@wangtianjideMBP Desktop % brew -v
Homebrew 3.6.12
Homebrew/homebrew-core (git revision 05dc85caaff; last commit 2022-11-24)
执行后如果报错
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
从报错来看,是说 /Library/Developer/CommandLineTools
不是 xcode-select 的有效路径
那么要做的就有两件事:
- 找到 xcode-select的有效路径
- 使用有效路径替换
https://raw.githubusercontent.com/Homebrew/install/master/install
文件中的/Library/Developer/CommandLineTools
查找 xcode-select的有效路径
xcode-select -p
wangtianji@wangtianjideMBP ~ % xcode-select -p
/Applications/Xcode.app/Contents/Developer
使用有效路径
/Applications/Xcode.app/Contents/Developer
替换 https://raw.githubusercontent.com/Homebrew/install/master/install 文件中的/Library/Developer/CommandLineTools
,将https://raw.githubusercontent.com/Homebrew/install/master/install 内容复制下来,将第306和315行两处的/Library/Developer/CommandLineTools
改为/Applications/Xcode.app/Contents/Developer
并保存名为 install的文件
3.进入保存的install文件目录下,执行
ruby -e "$(cat install)"
如果报错
==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/brew/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
Failed during: git fetch --force --tags origin
依次执行以下命令就可以正常使用
git config --global --unset http.proxy
git config --global --unset https.proxy
国内源安装
使用国内源快速安装HomeBrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
选择:1、中科大源即可 安装后配置(必须执行,否则安装软件会出错)
重要 1、执行 brew -V 命令 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