Mac安装homebrew

参考:链接1换源方法
链接2 最初原创换源1 https://my.oschina.net/shede333/blog/364468
链接3
链接4
链接5
仔细查看以上链接,大多问题都会解决。以下是自己的安装过程和经验。
1、 尝试使用官网安装方式

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

总是会报错(LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54等等),失败。

2、失败后,换源安装
2.1 首先终端输入:

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
	以上是将原网址内容导入到brew_install文件。

然后,在finder中用文本编辑器打开brew_install文件,替换
BREW_REPO = "https://github.com/Homebrew/brew".freeze
为其他源如:
BREW_REPO="https://git.coding.net/homebrew/homebrew.git".freeze
(本镜像源只镜像了 Homebrew 托管在 Bintray 上的二进制预编译包,所以只对这些二进制包有加速功能(Homebrew 大部分情况下使用该渠道下载安装软件)--参考其他链接)

2.2 一切准备就绪,开始安装:
在终端输入

 ruby ~/brew_install

2.3 出现如下代码时,不用等了,直接关掉命令窗口。否则会等待很久,并下载一段时间后出现诸多error。

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

(这是因为源不同,还需要换源,采用清华镜像安装)
2.4 进入安装好的homebrew的文件目录下,clone homebrew-core

cd /usr/local/Homebrew/Library/Taps/homebrew

git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

2.5 把homebrew repo切换为清华镜像

cd "$(brew --repo)"

git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

2.6 这时,终端会显示Already up-to-date.到此,homebrew就安装完毕了。再用brew doctor检查,若出现一些警告,可以忽略或再百度查看详情。

3.Mac Homebrew 更换中国源以及重置官方源,由链接https://www.jianshu.com/p/63bd1c567362。
在此复制,方便自己查看。

Homebrew安装主要靠git仓库,切换源实际上就是切换相关git repo的remote url.

具体做法:

找到brew.git和homebrew-core.git的本地repo
切换两个repo的remote url

切换USTC源:https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git

# 更换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

brew update

另外,还需要更换Homebrew Bottle源,这个只要在shell配置文件里加上(或更改)一个变量即可。
如zsh就是编辑~/.zshrc文件, bash就是~/.bash_profile文件:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

切换清华源:https://mirror.tuna.tsinghua.edu.cn/help/homebrew/

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

brew update

重置官方源:

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

# 重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值