在mac系統(tǒng)中,使用homebrew可以很方便的管理包。按照官網(wǎng)的說(shuō)明執(zhí)行以下命令時(shí)總是報(bào)錯(cuò):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
應(yīng)該是這個(gè)資源訪問(wèn)有問(wèn)題,那么我們可以嘗試使用國(guó)內(nèi)的鏡像。給大家推薦一個(gè)中科院的鏡像站點(diǎn),里面有各種資源:
https://mirrors.ustc.edu.cn/brew.git
言歸正傳,開(kāi)始踩坑
第一步,獲取install文件
把官網(wǎng)給的腳本拿下來(lái)
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
第二步,更改腳本中的資源鏈接,替換成清華大學(xué)的鏡像
就是把這兩句
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
當(dāng)然如果這個(gè)鏡像有問(wèn)題的話,可以換成別的
第三步,執(zhí)行腳本
/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
出現(xiàn)這個(gè)原因是因?yàn)樵床煌ǎa來(lái)不下來(lái),解決方法就是更換國(guó)內(nèi)鏡像源:
執(zhí)行下面這句命令,更換為中科院的鏡像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
就下載成功了
然后把homebrew-core的鏡像地址也設(shè)為中科院的國(guó)內(nèi)鏡像
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
執(zhí)行更新,成功:
brew update
最后用這個(gè)命令檢查無(wú)錯(cuò)誤:
brew doctor
這樣海外和已經(jīng)有系統(tǒng)全局代理設(shè)置的朋友們就可以直接使用 brew 命令安裝軟件了。
接著換源:
直接使用 Homebrew 還需要更改默認(rèn)源,不然誰(shuí)用誰(shuí)想打人,原因你懂的。以下是將默認(rèn)源替換為國(guó)內(nèi) USTC 源的方法。
替換核心軟件倉(cāng)庫(kù)
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替換 cask 軟件倉(cāng)庫(kù)(提供 macOS 應(yīng)用和大型二進(jìn)制文件)
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替換 Bottles 源(Homebrew 預(yù)編譯二進(jìn)制軟件包)
bash(默認(rèn) 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
基本用法:
假定操作對(duì)象為 wget,請(qǐng)?zhí)鎿Q為自己需要的軟件包名
操作 命令
更新 Homebrew brew update
更新所有安裝過(guò)的軟件包 brew upgrade
更新指定的軟件包 brew upgrade wget
查找軟件包 brew search wget
安裝軟件包 brew install wget
卸載軟件包 brew remove wget
列出已安裝的軟件包 brew list
查看軟件包信息 brew info wget
列出軟件包的依賴關(guān)系 brew deps wget
列出可以更新的軟件包 brew outdated
參考:
Homebrew 中文主頁(yè)
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
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/qq_35624642/article/details/79682979