Mac安装homebrew,并替换使用清华镜像源


Mac OS Mojave 10.14.5

1.在~/.bash_profile设置路径

if [[ "$(uname -s)" == "Linux" ]]; then BREW_TYPE="linuxbrew"; else BREW_TYPE="homebrew"; fi
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/${BREW_TYPE}-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/${BREW_TYPE}-bottles"

在terminal执行source ~/.bash_profile命令,使路径配置生效。

source ~/.bash_profile


2.从清华镜像下载安装脚本并安装 Homebrew / Linuxbrew

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

输入开机密码继续安装

==> Checking for sudo access (which may request your password).
Password:

brew -v测试homebrew是否安装成功

brew -v
Homebrew 3.1.2-2-g8853fb6
Homebrew/homebrew-core (git revision 91c19159ac; last commit 2021-04-15)
Homebrew/homebrew-cask (git revision 749fbfa712; last commit 2021-04-15)

表明安装成功

3.替换现有仓库上游
替换 brew 程序本身的源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

自动设置 macOS 系统上的 Homebrew

BREW_TAPS="$(brew tap)"
for tap in core cask{,-fonts,-drivers,-versions}; do
    if echo "$BREW_TAPS" | grep -qE "^homebrew/${tap}\$"; then
        # 将已有 tap 的上游设置为本镜像并设置 auto update
        # 注:原 auto update 只针对托管在 GitHub 上的上游有效
        git -C "$(brew --repo homebrew/${tap})" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git
        git -C "$(brew --repo homebrew/${tap})" config homebrew.forceautoupdate true
    else   # 在 tap 缺失时自动安装(如不需要请删除此行和下面一行)
        brew tap --force-auto-update homebrew/${tap} https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git
    fi
done

更换上游后需重新设置 git 仓库 HEAD
brew update-reset

Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.

4.尝试安装npm

brew install node
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/brotli-1.0.9.mojave.bottle.tar.gz
==> Downloading from https://homebrew.bintray.com/brotli-1.0.9.mojave.bottle.tar.gz
curl: (22) The requested URL returned error: 404 Not Found
Trying a mirror...
==> Downloading https://ghcr.io/v2/homebrew/core/brotli-1.0.9.mojave.bottle.tar.gz
==> Downloading from https://github.com/-/v2/packages/container/package/homebrew%2Fcore%2Fbrotli-1.0.9.m
curl: (22) The requested URL returned error: 404
Error: Failed to download resource "brotli"
Download failed: https://ghcr.io/v2/homebrew/core/brotli-1.0.9.mojave.bottle.tar.gz

安装失败,不知道为什么请求链接不对,真的很奇怪
希望大家能给予帮助


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM