5

Mac os:将Homebrew的下载源换成国内镜像增加下载速度(阿里云镜像)

 1 year ago
source link: https://v3u.cn/a_id_135
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Mac os:将Homebrew的下载源换成国内镜像增加下载速度(阿里云镜像)

首页 - Mac & Linux/2020-03-08

    可能所有的mac用户都遇到过下面这种操蛋情况,在网络环境不太好的时候,你满怀期望的敲下 brew install 应用名称,静静的等待安装结果时,Homebrew 在 Updating 的地方卡死了,真是令人沮丧,当然了,这不是Homebrew的错,Homebrew 是一款 Mac OS 平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。

    Homebrew 主要分两部分:git repo(位于 GitHub)和二进制 bottles,这两个网站在国内访问起来都慢的可以。接下来操作一下如何使用阿里云来加速这两部分的下载。

    我们可以考虑使用 阿里云 的 Homebrew 镜像源进行加速。

    假设你没有更换过镜像源,执行 brew 命令安装应用的时候,下面3 个仓库地址将影响你的下载速度:
    brew.git
    homebrew-core.git
    homebrew-bottles

    首先,更换 brew.git

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

    其后,更换 homebrew-core.git

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

     执行完上面的命令之后,运行 brew update 来更新一下下载地址

     随后,运行brew config 来检查一下地址是否更新成功

    

20200308015519_31879.png

    可以看到,更新成功了

    最后一步:更换 homebrew-bottles

    首先查看一下你的系统当前shell版本是多少

echo $SHELL

     根据版本不同,会输出 2 种结果,/bin/zsh 或 /bin/bash,根据不同类型运行不同的命令

    /bin/zsh

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

    /bin/bash

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

     这样就可以了。

     在某些极端情况下,比如说阿里云镜像挂了之类的,好吧,这还是有可能,你可能又想恢复默认的源,那么可以执行下面的命令进行下载源的恢复

# 重置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

     随后可以删掉 HOMEBREW_BOTTLE_DOMAIN 环境变量,将你终端文件 ~/.bash_profile 或者 ~/.zshrc 中的HOMEBREW_BOTTLE_DOMAIN这一行删掉,随后执行命令:     

source ~/.bash_profile
source ~/.zshrc




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK