Stories

Detail Return Return

Mac上HomeBrew安裝及換源教程 - Stories Detail

Mac上HomeBrew安裝及換源教程

        Mac的Mac OS系統來源於Unix系統,得益於此Mac系統的使用類似於Linux,因此Linux系統中的包管理概念也適用於Mac,而HomeBrew便是其中的一個優秀的包管理工具,而包管理工具是什麼呢?軟件包管理工具,擁有安裝、卸載、更新、查看、搜索等功能,在終端中通過簡單的指令可以實現各類功能包的管理,而不用關心各種依賴和文件路徑情況。因此無論是什麼驅動?開發工具?都可以在HomeBrew中進行快捷下載而不像Win下有着繁雜的環境管理。

安裝教程

    想要快速的檢查電腦中有無HomeBrew只需要一行命令

brew -v #檢查電腦是否存在HomeBrew

        如果終端打印了版本信息的話證明電腦中存在HomeBrew,如果打印未知命令的話代表電腦中沒有HomeBrew環境。

        類似於機器人開發中的魚香ROS可以一鍵安裝需要的環境,HomeBrew也提供了一鍵安裝的腳本以供用户一鍵進行安裝:

· 如果需要重新安裝請先卸載HomeBrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

· 一鍵安裝的命令(可能需要Science On The Net):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    如果遇到這個報錯:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused則代表網絡無法訪問需要Science On The Net,一般來説XXX網後這個安裝和下載的速度非常的迅速

附上常用的HomeBrew指令

· 想要查找HomeBrew的用户幫助界面可以輸入

brew -h 
brew help

· 查看HomeBrew的版本

brew -v

· 更新HomeBrew

brew update

HomeBrew換源命令

    HomeBrew默認的源在國外,平時正常使用非常的慢因此我們可以將其替換為國內源

· 查看當前源

cd "$(brew --repo)" && git remote -v

替換為清華源

# 替換各個源
$ 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

# zsh 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

替換為中科大源

# 替換各個源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# zsh 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 刷新源
$ brew update

Add a new Comments

Some HTML is okay.