MacOS配置homebrew
如默
撰写于 2023年 03月 02 日

说明

前两天买的Mac mini到货了,正好需要配置环境,折腾了一下,特此记录。

官网安装

首先,这里是官网:Homebrew,用官网的脚本安装,执行

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

如果网络没问题,会直接一路安装成功,但如果提示:

curl: Failed to connect to raw.githubusercontent.com port 443: Connection refused

需要修改/etc/hosts,在这个网站IP address,检测一下raw.githubusercontent.com,会得到这个域名的A解析,将对应的IP和域名,添加到hosts文件的最后,然后就可以顺利执行脚本了

国内脚本

上面的那个官网的,速度不是很理想,可以手动替换源地址,阿里,清华,中科大,腾讯都有。直接百度即可

# 科大
https://mirrors.ustc.edu.cn/help/brew.git.html

# 阿里
https://developer.aliyun.com/mirror/homebrew/

# 腾讯
https://mirrors.cloud.tencent.com/homebrew/

# 清华
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

脚本地址:HomebrewCN

这个脚本,很简单,可以自主选择要使用的国内源,很方便,安装完之后,根据提示运行命令即可

安装脚本命令

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

问题

下面记录遇到的几种问题以及解决办法

1,执行brew update遇到如下报错:

Error: Failed to download https://formulae.brew.sh/api/formula.jws.json!
Failed to download https://formulae.brew.sh/api/cask.jws.json!
==> Downloading https://formulae.brew.sh/api/formula.jws.json
                                                                           0.7%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Warning: formula.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/formula.jws.json
#                                                                          2.2%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Warning: formula.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/formula.jws.json
curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Error: Failure while executing; `/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --user-agent Homebrew/4.0.4-86-g7c15dce\ \(Macintosh\;\ arm64\ Mac\ OS\ X\ 13.2.1\)\ curl/7.86.0 --header Accept-Language:\ en --fail --progress-bar --location --remote-time --output /Users/rumosky/Library/Caches/Homebrew/api/formula.jws.json --compressed --speed-limit 100 --speed-time 5 --progress-bar https://formulae.brew.sh/api/formula.jws.json` exited with 28. Here's the output:
curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

执行这个命令即可

export HOMEBREW_NO_INSTALL_FROM_API=1

2,执行brew doctor时,遇到下面的提示:

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Suspicious https://github.com/Homebrew/brew git origin remote found.
The current git origin is:
  https://mirrors.aliyun.com/homebrew/brew.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/opt/homebrew" remote set-url origin https://github.com/Homebrew/brew

Warning: Suspicious https://github.com/Homebrew/homebrew-core git origin remote found.
The current git origin is:
  https://mirrors.aliyun.com/homebrew/homebrew-core.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/opt/homebrew/Library/Taps/homebrew/homebrew-core" remote set-url origin https://github.com/Homebrew/homebrew-core

这个忽略就好,不用管。

3,执行brew update,遇到下面的提示:

Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Already up-to-date.

再执行brew -v命令看看是不是有两个warning,这说明你的homebrew-core、homebrew-cask和homebrew-services目录被git认为不是一个安全的目录,需要手动添加

git config --global --add safe.directory 你的homebrew-core路径
git config --global --add safe.directory 你的homebrew-cask路径
git config --global --add safe.directory 你的homebrew-services路径

最后

阿里的文档很旧,内容没有更新,腾讯直接就没有文档,建议用清华和科大的,文档很详细,我最后用的是清华的,按照文档一步一步来,一点问题都没有,最后附上我的配置文件.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"
# Set PATH, MANPATH, etc., for Homebrew.
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
eval "$(/opt/homebrew/bin/brew shellenv)"

优先使用官方的脚本,觉得慢,就替换成国内的,实在不行,再用国内的脚本。

MacOS配置homebrew

温馨提示:

本文最后更新于2023年03月02日,已超过616天没有更新,若内容或图片失效,请留言反馈。

说明

前两天买的Mac mini到货了,正好需要配置环境,折腾了一下,特此记录。

官网安装

首先,这里是官网:Homebrew,用官网的脚本安装,执行

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

如果网络没问题,会直接一路安装成功,但如果提示:

curl: Failed to connect to raw.githubusercontent.com port 443: Connection refused

需要修改/etc/hosts,在这个网站IP address,检测一下raw.githubusercontent.com,会得到这个域名的A解析,将对应的IP和域名,添加到hosts文件的最后,然后就可以顺利执行脚本了

国内脚本

上面的那个官网的,速度不是很理想,可以手动替换源地址,阿里,清华,中科大,腾讯都有。直接百度即可

# 科大
https://mirrors.ustc.edu.cn/help/brew.git.html

# 阿里
https://developer.aliyun.com/mirror/homebrew/

# 腾讯
https://mirrors.cloud.tencent.com/homebrew/

# 清华
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

脚本地址:HomebrewCN

这个脚本,很简单,可以自主选择要使用的国内源,很方便,安装完之后,根据提示运行命令即可

安装脚本命令

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

问题

下面记录遇到的几种问题以及解决办法

1,执行brew update遇到如下报错:

Error: Failed to download https://formulae.brew.sh/api/formula.jws.json!
Failed to download https://formulae.brew.sh/api/cask.jws.json!
==> Downloading https://formulae.brew.sh/api/formula.jws.json
                                                                           0.7%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Warning: formula.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/formula.jws.json
#                                                                          2.2%curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Warning: formula.jws.json: update failed, falling back to cached version.
==> Downloading https://formulae.brew.sh/api/formula.jws.json
curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

Error: Failure while executing; `/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --user-agent Homebrew/4.0.4-86-g7c15dce\ \(Macintosh\;\ arm64\ Mac\ OS\ X\ 13.2.1\)\ curl/7.86.0 --header Accept-Language:\ en --fail --progress-bar --location --remote-time --output /Users/rumosky/Library/Caches/Homebrew/api/formula.jws.json --compressed --speed-limit 100 --speed-time 5 --progress-bar https://formulae.brew.sh/api/formula.jws.json` exited with 28. Here's the output:
curl: (28) Operation too slow. Less than 100 bytes/sec transferred the last 5 seconds

执行这个命令即可

export HOMEBREW_NO_INSTALL_FROM_API=1

2,执行brew doctor时,遇到下面的提示:

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Suspicious https://github.com/Homebrew/brew git origin remote found.
The current git origin is:
  https://mirrors.aliyun.com/homebrew/brew.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/opt/homebrew" remote set-url origin https://github.com/Homebrew/brew

Warning: Suspicious https://github.com/Homebrew/homebrew-core git origin remote found.
The current git origin is:
  https://mirrors.aliyun.com/homebrew/homebrew-core.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/opt/homebrew/Library/Taps/homebrew/homebrew-core" remote set-url origin https://github.com/Homebrew/homebrew-core

这个忽略就好,不用管。

3,执行brew update,遇到下面的提示:

Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Already up-to-date.

再执行brew -v命令看看是不是有两个warning,这说明你的homebrew-core、homebrew-cask和homebrew-services目录被git认为不是一个安全的目录,需要手动添加

git config --global --add safe.directory 你的homebrew-core路径
git config --global --add safe.directory 你的homebrew-cask路径
git config --global --add safe.directory 你的homebrew-services路径

最后

阿里的文档很旧,内容没有更新,腾讯直接就没有文档,建议用清华和科大的,文档很详细,我最后用的是清华的,按照文档一步一步来,一点问题都没有,最后附上我的配置文件.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"
# Set PATH, MANPATH, etc., for Homebrew.
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
eval "$(/opt/homebrew/bin/brew shellenv)"

优先使用官方的脚本,觉得慢,就替换成国内的,实在不行,再用国内的脚本。


那年今日
03月
02日
赞 (2)

猜您想看

  • 太平国家森林公园——记五一自驾游

    很早之前就计划五一出去玩,但是不知道去哪里。导师提到太平国家森林公园不错,遂决定前往。

    2019年05月14日
  • 简述Windows10多种激活密钥OEM、GVLK、KMS等的区别

    最近有的激活工具新出了数字激活方式,导致很多人分不清楚KMS,数字激活和OEM激活。本文就详细简单介绍一下。

    2021年02月23日
  • Docker指定latest标签

    之前发布了两个版本的docker文件,有1.0和2.0,默认使用latest标签应该指向最新的2.0版本,记录一下

    2023年05月30日
  • 铭瑄 RTX3060Ti iCraft OC 8G 独立显卡

    前两天买了一个技嘉小雕 RX 6750XT ELITE 12G独立显卡,结果各种掉驱动,黑屏,打游戏听风扇狂转,虽然温度不高,但总感觉不踏实。趁还没过七天无理由,赶紧退了,换了N卡。

    2022年12月24日
  • JMeter压力测试工具初体验

    Apache JMeter是Apache组织开发的基于Java的压力测试工具。

    2020年07月12日
  • Docker自动更新镜像方法(定时任务或Watchtower)

    平时运行docker如果需要更新,则需要先停止原来的容器,更新新的镜像,然后再创建新容器,这样操作虽然不繁琐,但是如果容器过多,还是会很麻烦,本文记录一下如何简化自动更新。

    2023年11月22日

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论

Vaptcha 初始化中...