美文网首页Xcode项目构建
Mac下使用国内镜像安装Homebrew

Mac下使用国内镜像安装Homebrew

作者: SkyMing一C | 来源:发表于2019-06-29 14:22 被阅读5次

    安装 Homebrew

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

    将以上命令粘贴至终端。

    Mac下使用国内镜像安装Homebrew

    在Mac下Homebrew安装缓慢或提示"Failed during: git fetch origin master:refs/remotes/origin/master --tags --force)"

    error: RPC failed; curl 18 transfer closed with outstanding read data remaining
    fatal: The remote end hung up unexpectedly
    fatal: early EOF
    fatal: index-pack failed
    Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
    
    其解决方案为使用国内镜像安装Homebrew

    实现步骤

    1. 将brew的install文件下载本地
    cd ~
    
    curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
    
    2. 编辑brew_install文件
    vim 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 和CORE_TAP_REPO(如果存在的话)替换为

    BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
    CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze
    
    3. 安装
    /usr/bin/ruby ~/brew_install
    
    4. 替换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
    
    5. brew更新
    brew update
    
    6. 设置 bintray镜像
    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
    source ~/.bash_profile
    
    7. 检查
    brew doctor
    

    参考

    Homebrew 中文主页

    Mac下使用国内镜像安装Homebrew

    相关文章

      网友评论

        本文标题:Mac下使用国内镜像安装Homebrew

        本文链接:https://www.haomeiwen.com/subject/brhpcctx.html