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日,已超过416天没有更新,若内容或图片失效,请留言反馈。

说明

前两天买的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)

猜您想看

  • Windows 11正式版发布,官方原版ISO下载以及使用体验

    Windows 11正式版发布,记录一下官方原版ISO下载以及使用体验

    2021年10月07日
  • Visual Studio Code插件koro1FileHeader使用记录

    VS code是一个非常方便的工具,加上免费,所以一直在使用。 本文记录一下此插件的配置过程以及配置文件,方便以后使用。

    2019年05月15日
  • 中国建设银行甘肃省分行2021秋季校招面试经验

    如题,参加了建行的秋招,记录一下,分享经验

    2020年11月29日
  • typecho原生微信小程序

    一直想把网站做成小程序,github上typecho的小程序也都是远古版本,今年官方也升级到了typecho 1.2.1版本,目前还没有可用的小程序,我自己抽空写了一个,开源给大家使用。

    2023年07月18日
  • 2020年秋招小结

    2020秋招已经基本结束,除了少数银行之类的企业还在等最后的通知,在这几个月里,忙前忙后,在此小结一下。

    2020年12月26日
  • 神州数码实习小结

    学校在今年的九月安排实习,实习到十月底,公司是神州数码信息股份有限公司西安分公司,准确的来说应该是神州数码融信股份有限公司,听说是要改名了,不过仍然是DCTIS

    2020年11月02日

评论区(暂无评论)

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

我要评论

Vaptcha 初始化中...