到Github官網上搜索Homebrew,找到對應的Homebrew後,查看它的安裝文檔,鏈接如下:
https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Installation.md
打開Mac的終端。進入該路徑,然後執行安裝文檔中的命令即可。
cd /usr/local
mkdir homebrew
curl -L https://github.com/Homebrew/homebrew/tarball/master | tar xz --strip 1 -C homebrew
上面的安裝只是將Homebrew解壓到本地,還需要配置環境變量才能使用brew命令,否則終端會提示Command Not Found。
第一次配置Mac的環境變量,到網上轉了一圈才找到正確方法。
打開終端,新建.bash_profile文件在~/目錄下
touch ~/.bash_profile
open ~/.bash_profile
在彈出的編輯窗口中配置PATH
export PATH=/usr/local/homebrew/bin:$PATH
然後再回到終端輸入,使文件生效。
source ~/.bash_profile
至此,環境變量配置完成。