Macos更換國內源安裝Homebrew

安裝過程緩慢可以替換安裝源爲國內的源。

以更換清華源爲例,喜歡其他源的可以參照以下方法:

  1. ​ 先自己下載官方的安裝文件:

    • 如果有wget,嘗試使用wget下載

      wget https://raw.githubusercontent.com/Homebrew/install/master/install -O install.rb
      
    • 直接在瀏覽器打開網址:https://raw.githubusercontent.com/Homebrew/install/master/install,看到的內容全部複製下來保存在文件裏,並命名爲install.rb

  2. 修改官方文件裏面的源:

    ​ 在BREW_REPO = "https://github.com/Homebrew/brew".freeze前加#

    ​ 在下方加入一行:BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze

然後直接執行ruby install.rb進行安裝。

錯誤解決

Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.

在克隆倉庫時出錯,通過手動克隆解決,手動克隆時推薦使用清華開源軟件鏡像站的倉庫。

  1. 首先進入brew的repo目錄:cd "$(brew --repo)"
  2. 進入Library/Taps
  3. 創建並進入目錄:mkdir homebrew && cd homebrew
  4. 克隆倉庫:git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

爲了防止出現其他錯誤,克隆其他倉庫下來:

git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

克隆下來的倉庫記得保存在目錄"$(brew --repo)"/Library/Taps/homebrew下。

克隆後再次執行ruby install.rb

使用過程中更換爲國內的源使用起來更加舒適

更換brew的源爲清華源:

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
brew update

更改bintray鏡像:

臨時更改:export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles

長期更改:

  • bash用戶

    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
    source ~/.bash_profile
    
  • zsh用戶

    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
    source ~/.zshrc
    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章