Mac下使用国内镜像安装Homebrew

Mac下使用国内镜像安装Homebrew

First

MBP上的brew很老了,就想把brew更新一下,顺便安装一下NodeJs。无奈更新的过程一直卡在网络下载,毫不动弹。想想,应该是Repo访问不到的原因,于是重装brew。

根据官网上的方法,在终端输入:

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

结果还是被卡在下载阶段,怎么办呢?于是上网搜索到了“Homebrew 的安装方法(官方的方法老是安装失败) 第三方”这篇文章。

依文中所述,进行安装。由于官方弃用了旧的homebrew仓库,将homebrew程序与软件包拆分成了两个仓库。与文中描述不符,也未能成功安装。于是稍作修改,记录于此。

国内的镜像

新增brew.git与homebrew-core.git镜像

由于官方弃用了旧的homebrew仓库,将homebrew程序与软件包拆分成了两个仓库。为保证用户正常升级,旧镜像将暂时保留一段时间,择期删除。

仓库对应关系:

github.com/Homebrew/brew -> mirrors.ustc.edu.cn/brew.git
github.com/Homebrew/homebrew-core -> mirrors.ustc.edu.cn/homebrew-core.git
github.com/Homebrew/homebrew(弃用) -> mirrors.ustc.edu.cn/homebrew.git

引自:新增brew.git与homebrew-core.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 = "git://mirrors.ustc.edu.cn/brew.git".freeze
#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
CORE_TAP_REPO = "git://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 = "git://mirrors.ustc.edu.cn/brew.git".freezeCORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze

安装

/usr/bin/ruby ~/brew_install 

运行修改了的brew_install文件。

替换homebrew源

替换homebrew默认源

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

替换homebrew-core源

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

brew更新

brew update

设置 bintray镜像

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

 

55人点赞

 

技术开发

 



作者:采姑娘的小魔钴
链接:https://www.jianshu.com/p/6523d3eee50d
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!如果您想在国内使用Homebrew并加速安装速度,可以使用清华大学开源软件镜像站提供的镜像安装Homebrew。以下是在Mac安装Homebrew的步骤: 1. 打开终端应用程序(Terminal),可以在Launchpad的"其他"文件夹中找到它。 2. 在终端中输入以下命令并按下回车键,以安装Homebrew: ```shell /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)" ``` 3. 安装过程可能需要一些时间,等待安装完成。 4. 安装完成后,您可以使用以下命令验证Homebrew是否正确安装: ```shell brew doctor ``` 如果看到"Your system is ready to brew."的提示,说明Homebrew已成功安装。 通过使用清华大学镜像站提供的国内镜像,您可以加快Homebrew的下载和更新速度。对于许多软件包,您只需将默认的Homebrew源更改为清华大学镜像即可。以下是如何更改Homebrew源为清华大学镜像的步骤: 1. 在终端中输入以下命令,备份当前Homebrew源: ```shell cd "$(brew --repo)" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git ``` 2. 接下来,需要备份Homebrew核心(Homebrew Core)的源。输入以下命令备份Homebrew核心: ```shell cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git ``` 3. 最后,使用以下命令更新Homebrew: ```shell brew update ``` 现在,您已经成功更改了Homebrew的源为清华大学镜像,可以享受更快的下载和更新速度了!请注意,如果您之前已经安装Homebrew,可能需要重新安装某些软件包。 希望这些信息能对您有所帮助!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值