在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 源的方法。
替換核心軟件倉庫
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替換 cask 軟件倉庫(提供 macOS 應用和大型二進制文件)
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替換 Bottles 源(Homebrew 預編譯二進制軟件包)
bash(默認 shell)用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.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
基本用法:
假定操作對象為 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 源使用幫助
http://mirrors.ustc.edu.cn/help/homebrew-core.git.html
---------------------
作者:QC班長
來源:CSDN
原文:https://blog.csdn.net/qq_35624642/article/details/79682979
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!