一.換源
方法一:
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試試。
3.替換成國內源
替換homebrew默認源
cd "$(brew --repo)"
/usr/local/Homebrew
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替換homebrew-core源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替換homebrew-cask源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
4.設置 bintray鏡像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
5.更新
brew update
6.踩坑
6.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
6.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安裝位置
參考:
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