Mac安装homebrew和brew cask

在mac系统中,使用homebrew可以很方便的管理包.

官网提供的安装指令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

执行起来总是结果还是被卡在下载阶段,报错如下:LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

应该是这个资源访问有问题,那么我们可以尝试使用国内的镜像(中科大,清华)。 
中科大源 https://mirrors.ustc.edu.cn/brew.git 

 

一. 获取install文件

cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

二.更改脚本中的资源链接,替换成中科大的镜像

编辑brew_install文件

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/Homebrew/brew/tarball/master anywhere you like or
# change the value of HOMEBREW_PREFIX.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
CORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze

注释掉BREW_REPO = "https://github.com/Homebrew/brew".freezeCORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze

修改为BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freezeCORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze

 

第三步,执行安装Homebrew脚本

/usr/bin/ruby brew_install

然后可以看到这几句: 

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core

出现这个原因是因为源不通,代码来不下来,解决方法就是更换国内镜像源:

执行下面这句命令,更换为中科院的镜像就下载成功了

 git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

替换homebrew和homebrew-core的镜像地址为中科院的国内镜像

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

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

执行更新,成功:

brew update

最后用这个命令检查无错误:

brew doctor

这样就可以直接使用 brew 命令安装软件了。

 

第四步:安装brew cask

brew 安装完毕,安装brew cask

brew install caskroom/cask/brew-cask

出现error:

Error: Cask 'brew-cask' is unavailable: '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/Casks/brew-cask.rb' does not exist. 

解决方法如下:

brew install brew-cask-completion

测试输入如下:

brew cask search qq

返回结果如下则成功:

==> Exact Match
qq
==> Partial Matches
qqbrowser       qqinput         qqlive          qqmacmgr        qqmusic

替换brew cask的镜像地址为中科院的国内镜像

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

 

第五步. 替换 Bottles 源

Homebrew Bottles是Homebrew提供的二进制代码包,目前镜像站收录了以下仓库:

  • homebrew/homebrew-core

  • homebrew/homebrew-dupes

  • homebrew/homebrew-games

  • homebrew/homebrew-gui

  • homebrew/homebrew-python

  • homebrew/homebrew-php

  • homebrew/homebrew-science

  • homebrew/homebrew-versions

  • homebrew/homebrew-x11

替换方式如下

  • bash(默认 shell)用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
  • 对于zsh用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

      

参考:

执行 brew install 命令长时间卡在 Updating Homebrew 的解决方法

https://learnku.com/articles/18908

Homebrew 中文主页

https://brew.sh/index_zh-cn.html

 Homebrew Bottles 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-bottles.html

 Homebrew Cask 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html

 Homebrew Core 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-core.git.html

 

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值