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