在mac系統中,使用homebrew可以很方便的管理包。按照官網的說明執行以下命令時總是報錯: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
應該是這個資源訪問有問題,那麼我們可以嘗試使用國內的鏡像。給大家推薦一箇中科院的鏡像站點,裏面有各種資源:
https://mirrors.ustc.edu.cn/brew.git
言歸正傳,開始踩坑
第一步,獲取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
然後可以看到這幾句:
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core
liyuanbadeMacBook-Pro:~ liyuanba$ git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
出現這個原因是因爲源不通,代碼來不下來,解決方法就是更換國內鏡像源:
執行下面這句命令,更換爲中科院的鏡像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
就下載成功了
然後把homebrew-core的鏡像地址也設爲中科院的國內鏡像
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
執行更新,成功:
brew update
最後用這個命令檢查無錯誤:
brew doctor
這樣海外和已經有系統全局代理設置的朋友們就可以直接使用 brew 命令安裝軟件了。
接着換源:
直接使用 Homebrew 還需要更改默認源,不然誰用誰想打人,原因你懂的。以下是將默認源替換爲國內 USTC 源的方法。
替換核心軟件倉庫
替換 cask 軟件倉庫(提供 macOS 應用和大型二進制文件)
替換 Bottles 源(Homebrew 預編譯二進制軟件包)
bash(默認 shell)用戶:
zsh 用戶:
基本用法:
假定操作對象爲 wget,請替換爲自己需要的軟件包名
操作 | 命令 |
更新 Homebrew | brew update |
更新所有安裝過的軟件包 | brew upgrade |
更新指定的軟件包 | brew upgrade wget |
查找軟件包 | brew search wget |
安裝軟件包 | brew install wget |
卸載軟件包 | brew remove wget |
列出已安裝的軟件包 | brew list |
查看軟件包信息 | brew info wget |
列出軟件包的依賴關係 | brew deps wget |
列出可以更新的軟件包 | brew outdated |
參考:
Homebrew 中文主頁
https://brew.sh/index_zh-cn.html
Homebrew Bottles 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-bottles.html
Homebrew Cask 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html
Homebrew Core 源使用幫助