Brew install xxxx长期停留在Updating Homebrew...

由于国内某种特殊原因,我们访问很多repo源是有一定难度的,比如在Mac上非常好用的包管理软件Brew默认是没有安装的,所以需要我们首先安装Brew:

 

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

此时Brew已经安装成功了,但当我们满心欢喜以为大快朵颐的安装各种工具时发现居然报错,下载不了这,连接那又timeout,什么也安装不了,心肝迷茫和无助。

 

eric@EricdeMacBook-Pro ~ % brew install python3 
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
aws-sdk-cpp    fonttools      hsd            memcached      mpd            okteto         pspg           sqlmap
bmake          gmsh           hwloc          mercurial      nethogs        onscripter     pueue          strongswan
cfn-lint       goreleaser     libvirt        minio          nfdump         openimageio    quantlib
cimg           grpc           libzdb         minio-mc       nim            pagmo          shunit2
cjson          haproxy        mdbook         monolith       nomad          phpmd          spim

==> Installing dependencies for python: openssl@1.1, sqlite and xz
==> Installing python dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1f.catalina.bottle.tar.gz
-=O=-  #   #   #     #                                                        
curl: (7) Failed to connect to akamai.bintray.com port 443: Operation timed out
Error: Failed to download resource "openssl@1.1"
Download failed: https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1f.catalina.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading https://www.openssl.org/source/openssl-1.1.1f.tar.gz
######################################################################## 100.0%
==> perl ./Configure --prefix=/usr/local/Cellar/openssl@1.1/1.1.1f --openssldir=/usr/local/etc/openssl@1.1 no-ssl3 no-
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl@1.1/1.1.1f/share/man MANSUFFIX=ssl
==> 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.

问题解决方案

其实这一切的问题是在于我们安装的brew默认repo是官方的repo,出于国内特色原因无法连接;所以使用 Alibaba 的 Homebrew 镜像源进行加速后问题就迎刃而解。
平时我们执行 brew 命令安装软件的时候,跟以下 3 个仓库地址有关:

  1. brew.git
  2. homebrew-core.git
  3. homebrew-bottles

1. 替换brew.git 仓库地址:

 

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

还原

 

cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

2. 替换homebrew-core.git 仓库地址:

 

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

还原

 

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

3. 替换homebrew-bottles 访问地址

这个步骤跟你的 macOS 系统使用的 shell 版本有关系,先来查看当前使用的 shell 版本

 

echo $SHELL
/bin/zsh

3.1 zsh替换成阿里巴巴的 homebrew-bottles 访问地址:

 

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

还原

 

vi ~/.zshrc
# 然后,删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置
source ~/.zshrc

3.2 bash替换成阿里巴巴的 homebrew-bottles 访问地址:

 

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

还原

 

vi ~/.bash_profile
# 然后,删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置
source ~/.bash_profile

配置完后再去安装下某些工具和module时就能发现畅快无比了

 

eric@EricdeMacBook-Pro homebrew-core % brew install python3 
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/python-3.7.7.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring python-3.7.7.catalina.bottle.tar.gz
==> /usr/local/Cellar/python/3.7.7/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> /usr/local/Cellar/python/3.7.7/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> /usr/local/Cellar/python/3.7.7/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺  /usr/local/Cellar/python/3.7.7: 4,006 files, 61.2MB



作者:瞄不准的亚瑟
链接:https://www.jianshu.com/p/9ad2fe2b2c23
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐