当前位置: 首页 > news >正文

【homebrew安装】踩坑爬坑教程

homebrew官网,有安装教程提示,但是在实际安装时,由于待下载的包的尺寸过大,本地git缓存尺寸、超时时间的限制,会报如下错误:

error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly:CANCEL
error: RPC failed; curl 18 transfer closed with outstanding read data remaining

一、安装

执行命令:

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

二、git设置

macos在安装时可能会遇到如上述的报错,可以增加以下设置

1. 增加 git 的缓冲区大小

增大 Git 缓冲区可以帮助解决传输中断问题:

git config --global http.postBuffer 524288000

2. 调整 Git 的传输超时

可以通过增加 Git 的超时时间来防止网络不稳定引起的中断:

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

3. 使用浅克隆

如果你在克隆 Homebrew 的仓库,可以使用浅克隆来减少传输的数据量:

git clone --depth=1 https://github.com/Homebrew/brew.git

设置完成后,git配置如下:

4. 尝试使用镜像源

执行上述安装脚本时,走到Updating brewing时,可能会出现如下报错:

Error: Failed to download https://formulae.brew.sh/api/formula.jws.json!

看到这个报错时,基础功能已经安装成功,可能是网络问题,连接 Homebrew 官方服务器可能不稳定,特别是在中国等网络环境受限的地区。可以尝试使用国内镜像源。

设置国内源(清华大学镜像):

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc  # 或 ~/.bashrc

设置国内源(阿里云镜像):

git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc  # 或 ~/.bashrc

1、如果提示brew命令行不存在,那么请先按照下面第2节,配置brew的bin文件到环境变量Path中,brew命令行就能生效。然后再执行上述命令,去修改源。

2、如果报如下错:fatal: cannot change to '/opt/homebrew/Library/Taps/homebrew/homebrew-core': No such file or directory,则表示Homebrew 核心库(homebrew-core)没有正确安装,可以先手动安装:

# 创建 Homebrew taps 目录
mkdir -p "$(brew --repo)/Library/Taps/homebrew"# 克隆 homebrew-core 仓库到本地
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

3、如果报如下错:fatal: cannot change to '/opt/homebrew/Library/Taps/homebrew/homebrew-cask': No such file or directory,则表示Homebrew 核心库(homebrew-cask)没有正确安装,可以先手动安装:

# 创建 Homebrew Taps 目录
mkdir -p "$(brew --repo)/Library/Taps/homebrew"# 克隆 homebrew-cask 仓库到本地
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"

2. 确认 Homebrew 安装路径

如果安装成功,但 brew 命令依然无法找到,可能是 Homebrew 的路径没有正确配置。首先,检查 Homebrew 是否已经安装并找到安装路径。

在 Apple Silicon Mac 上,Homebrew 通常会安装在 /opt/homebrew,而在 Intel Mac 上,通常会安装在 /usr/local. 你可以手动添加 Homebrew 的路径到你的 PATH 环境变量中。

2.1. (M1/M2) 芯片Mac:

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

2.2. Intel 芯片Mac:

echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"

然后,重新启动终端或执行以下命令以重新加载配置:

source ~/.zprofile

3. 验证 Homebrew 安装

在重新安装并配置 PATH 之后,运行以下命令检查 Homebrew 是否安装成功:

brew --version

如果你看到 Homebrew 的版本信息,说明安装成功并配置正确。

成功后,显示如下:
在这里插入图片描述


http://www.mrgr.cn/news/33384.html

相关文章:

  • Renesas R7FA8D1BH (Cortex®-M85) 生成4路PWM
  • 【ArcGIS微课1000例】0123:数据库中要素类批量转为shapefile
  • 数据结构之堆(优先级队列)
  • 2024/9/22周报
  • 【面经】查找中常见的树数据结构
  • 8. Data Member的绑定
  • 国产游戏技术能否引领全球【终稿】
  • CompletableFuture如何优雅处理异步任务超时!妙就完了
  • 国人卖家可折叠无线充电器发起TRO专利维权,功能相同可能侵权
  • 【深入学习Redis丨第六篇】Redis哨兵模式与操作详解
  • 图神经网络的新篇章:通用、强大、可扩展的图变换器
  • WebGL基础知识快速入门
  • 空栈压数 - 华为OD统一考试(E卷)
  • thinkphp 做分布式服务+读写分离+分库分表(分区)(后续接着写)
  • 【shell脚本4】Shell脚本学习--字符串和数组
  • 掌控历史:如何通过Git版本管理工具提升你的开发效率
  • 2024华为杯E题成品文章已出!
  • 【AI算法岗面试八股面经【超全整理】——深度学习】
  • 软件开发事故分级极简理解(灾难级、高级、中级、轻微级)
  • 学习C4模型的新网站