Homebrew切換為國內鏡像源


1、brew.git 鏡像

中科大鏡像:https://mirrors.ustc.edu.cn/brew.git
 
阿里鏡像:  https://mirrors.aliyun.com/homebrew/brew.git
 
清華鏡像:https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
 
GitHub鏡像:https://github.com/Homebrew/brew.git

2、homebrew-core.git 鏡像

中科大鏡像:https://mirrors.ustc.edu.cn/homebrew-core.git
 
阿里鏡像:  https://mirrors.aliyun.com/homebrew/homebrew-core.git
 
清華鏡像:https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
 
GitHub鏡像:https://github.com/Homebrew/homebrew-core

3、homebrew-cask.git 鏡像

# 中科大鏡像
https://mirrors.ustc.edu.cn/homebrew-cask.git
# 阿里暫無該鏡像
 
# github鏡像
https://github.com/Homebrew/homebrew-cask.git

一、切換 Homebrew 鏡像源為中科大鏡像源

1、替換源

以中科大鏡像為例

# 替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
 
# 替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
 
# 替換homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
 
# 應用生效
brew update
# 替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

2. 查看鏡像源信息

brew config

二、切換Homebrew 鏡像源為阿里鏡像源

1. 更換為阿里源

    # 替換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
    # 替換homebrew-bottles:
    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc

2. 查看鏡像源信息

brew config

三、重置 Homebrew 鏡像源

1. 切回官方原始鏡像(GitHub)

# 替換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-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
 
# 應用生效
brew update
 
# 刪除.zshrc變量
vim  ~/.zshrc
# 刪除如下變量
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
 
# 執行更新
source ~/.zshrc

2.  查看鏡像源信息

brew config

四、非常規操作及常見問題解決
一.換源安裝homebrew
方法一:
1.卸載
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
2.安裝
方法一:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
方法二:
把官網給的腳本拿下來 
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
更改腳本中的資源鏈接,替換成中國科學技術大學的鏡像:
BREW_REPO = “https://github.com/Homebrew/brew“.freeze 
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze 
更改為這兩句 
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze 
CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze 
執行腳本
/usr/bin/ruby brew_install


二. 安裝常見問題, ping https://github.com試試。


1.替換成國內源,參考如上步驟,建議修改為阿里的源

2. 踩坑
2.1
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': transfer closed with outstanding read data remaining
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
分析:
網絡問題,手工下載。
創建目錄:
cd "$(brew --repo)"
cd Library/Taps/
mkdir homebrew
cd homebrew/
mkdir homebrew-core
cd homebrew-core/
開始clone
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core


2.2
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
-bash: cd: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask: No such file or directory
$ brew cask install atom
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'…
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/': transfer closed with outstanding read data remaining
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-cask /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask —depth=1` exited with 128.
分析:
故障原因和上面一樣,處理方式也一樣就可以了。
創建目錄:
mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
開始clone
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

三. 常用命令
brew search <package_name> # 搜索
brew install <package_name> # 安裝一個軟件
brew uninstall <package_name> # 卸載一個軟件
brew update # 從服務器上拉取,並更新本地 brew 的包目錄
brew upgrade <package_name> # 更新一個軟件
brew upgrade # 更新全部已安裝軟件
brew outdated # 查看你的軟件中哪些有新版本可用
brew cleanup # 清理老版本。使用 `-n` 參數,不會真正執行,只是打印出真正運行時會做什么。
brew list --versions # 查看你安裝過的包列表(包括版本號)
brew link <package_name> # 將軟件的當前最新版本軟鏈到`/usr/local`目錄下
brew unlink <package_name> # 將軟件在`/usr/local`目錄下的軟鏈接刪除。
brew info # 顯示軟件的信息 
brew deps # 顯示包依賴
brew doctor # 檢查brew軟件的安裝是否正常
brew prune # 移除鏈接失效的文件
brew --cache # 打印下載軟件的緩存路徑
brew --config # 打印brew的配置信息
brew --env # 打印brew的環境信息
brew --prefix # 打印prefix的路徑(通常是/usr/local/)
brew --prefix [formula] # 指出formula安裝位置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM