Homebrew 安装包失败 & 切换源 & 安装缓慢的解决过程

5,224 阅读3分钟

受某篇队列相关的教程安利,它简单的写下了 brew install rabbitmq 就开始介绍知识。笔者信了它的邪,装此包时,从 23:00 一直到 1:30,其中切换了两个源才解决 brew update 慢的问题,切换了控制台的全局代理才解决下下载一个 github 上的 278MB 的包非常慢的问题,过程中还遇到了 Error: Permission denied 让我上火的事情。

下面我们开始第一步

$ brew install rabbitmq
Updating Homebrew...
==> Installing dependencies for rabbitmq: openssl@1.1, libpng, wxmac and erlang
==> Installing rabbitmq dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/d7/d7f992ebfd78f80828051f6dc6a1a99aed405f86b0f39ea651fd0afeadd1b0f4?__gda__=exp=1575992421~hmac=b48a88a6d35b1220627bfad07c5a04984d66b
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing rabbitmq dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.37.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/c8/c8e74da602c21f978cd7ee3d489979b4fc6681e71f678a1d99012943ee3a909f?__gda__=exp=1575992686~hmac=4d6ee4ada7eb7957714e216640b9a0dd005fa
######################################################################## 100.0%
==> Pouring libpng-1.6.37.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.37: 27 files, 1.2MB
==> Installing rabbitmq dependency: wxmac
==> Downloading https://homebrew.bintray.com/bottles/wxmac-3.0.4_2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/76/763d404a9adfadf2fa2099df378e6fb360b2b862c86e7e79413df9ed6e0da7a4?__gda__=exp=1575992702~hmac=2a59130d1b77ebbd7a3bc28491f7845762fb0
######################################################################## 100.0%
==> Pouring wxmac-3.0.4_2.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/wxmac/3.0.4_2: 810 files, 22.9MB
==> Installing rabbitmq dependency: erlang
==> Downloading https://homebrew.bintray.com/bottles/erlang-22.1.4.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/8b/8b6c056f129a6677a9886c8fd9972ec13bd25d2f79819acb556e461668d3ea34?__gda__=exp=1575992739~hmac=d2eaedbb42c65514d514e88e3e5caf8e9f22f
######################################################################## 100.0%
==> Pouring erlang-22.1.4.catalina.bottle.tar.gz
==> Caveats
Man pages can be found in:
  /usr/local/opt/erlang/lib/erlang/man

Access them with `erl -man`, or add this directory to MANPATH.
==> Summary
🍺  /usr/local/Cellar/erlang/22.1.4: 5,768 files, 280.2MB
==> Installing rabbitmq
==> Downloading https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.0/rabbitmq-server-generic-unix-3.8.0.tar.xz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/924551/71891480-e44b-11e9-80fd-c06739f04c5e?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AK
#                                                                          1.8%
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: An exception occurred within a child process:
  DownloadError: Failed to download resource "rabbitmq"
Download failed: https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.0/rabbitmq-server-generic-unix-3.8.0.tar.xz

卡到了着!于是我单独去下载了此文件 rabbitmq-server-generic-unix-3.8.0.tar.xz,并拷贝到 brew 的目录下

$ brew --cache
/Users/everlose/Library/Caches/Homebrew

$ cp /Users/everlose/Downloads/rabbitmq-server-generic-unix-3.8.0.tar.xz /Users/everlose/Library/Caches/Homebrew

然后在运行安装命令,发现卡在

$ brew install rabbitmq --verbose
Updating Homebrew...

这次连 update 都进行不下去!抓狂!!!

调试 verbose

$ brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...

进行不下去了,得,通通把源都切换去国内得吧,切换成中科大的,链接这里:lug.ustc.edu.cn/wiki/mirror…

# 替换brew.git:
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

# 替换homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 替换homebrew-cask
$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

再替换Homebrew Bottles源,参考 Homebrew Bottles 源使用帮助

# 对于 bash 用户
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

再次更新就非常成功。

$ brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
remote: Counting objects: 8714, done.
remote: Compressing objects: 100% (3829/3829), done.
remote: Total 8714 (delta 6404), reused 7173 (delta 4885)
Receiving objects: 100% (8714/8714), 5.64 MiB | 946.00 KiB/s, done.
Resolving deltas: 100% (6404/6404), completed with 976 local objects.
From https://mirrors.ustc.edu.cn/homebrew-cask
   18d8097421..1ee436843e  master     -> origin/master
Updating /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.

.......

然后继续安装,下载到一半又卡住了,因为它要去 github 上下载一个 278 MB的东西(当时忘了保存控制台里的内容,如果有人事后能提供我感激不尽),下载速度真的太感人了。我临时配置一下,让终端能走我配置的 v2r*y(某个说出来就违规的东西) 代理。如果你没有代理,那么恭喜你要忍受极度慢的下载速度了。

export ALL_PROXY=socks5://127.0.0.1:1080

# 事后想取消全局代理的话
export ALL_PROXY=""
# 不行的话试试
unset ALL_PROXY;

下载没问题了,但是权限又出麻烦,详见 github.com/Homebrew/ho…

Error: Permission denied @ apply2files - /usr/local/lib/node_modules/hexo/node_modules/nunjucks/node_modules/micromatch/lib/.DS_Store

删除这个毛文件,再次安装其实还出现了两次 .DS_Store 的权限问题,都删光后安装就搞定了。

$ rm -rf /usr/local/lib/node_modules/hexo/node_modules/nunjucks/node_modules/micromatch/lib/.DS_Store
...
$ brew install rabbitmq

Warning: rabbitmq 3.8.2 is already installed and up-to-date
To reinstall 3.8.2, run `brew reinstall rabbitmq`

然后启动试试

进入安装目录
$ /usr/local/Cellar/rabbitmq/3.8.2
启动
$ sbin/rabbitmq-server

浏览器输入 http://localhost:15672/#/

默认用户名密码 guest 访问

讲真,太折腾了。