1. 程式人生 > 其它 >mac homebrow 安裝與配置2021年12月13日

mac homebrow 安裝與配置2021年12月13日

Homebrew 是什麼

Homebrew是 mac的包管理器,僅需執行相應的命令,就能下載安裝需要的軟體包,可以省掉自己去下載、解壓、拖拽(安裝)等繁瑣的步驟。

比如安裝伺服器 nginx,開啟終端執行以下命令即可安裝:

brew install nginx

如何安裝?

方法二:使用brew映象安裝

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

執行到最後提示安裝成功,

然後執行brew -v,brew提示:command not found 解決方法

修改配置:

vim ~/.bash_profile

開啟終端輸入 brew提示:command not found 解決方法

輸入命令:

sudo vim .bash_profile

然後輸入以下程式碼:

export PATH=/usr/local/bin:$PATH

再使用以下命令使配置生效:

source .bash_profile

這樣就可以使用brew命令了

Homebrew安裝完為何需要配置

前面已經提到,Homebrew通常用來下載軟體的,但它在安裝軟體時非常慢。為了提升安裝速度,需要更改 Homebrew 的安裝源,將其替換成國內映象。

這裡用的是由中科大負責託管維護的 Homebrew 映象。其中,前兩個為必須配置的專案,後兩個可按需配置。

1.必備設定

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

2.按需設定

  • 替換 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
  • 替換homebrew-bottles:

首先要先區分你的mac用哪種終端工具,如果是 bash,則執行:

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

注:Homebrew 主要由四個部分組成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它們對應的功能如下:

組成功能
Homebrew 原始碼倉庫
homebrew-core Homebrew 核心源
homebrew-cask 提供macos應用和大型二進位制檔案的安裝
homebrew-bottles 預編譯二進位制軟體包

Homebrew 基本用法有哪些

// 查詢:
brew search 軟體名

// 安裝:
brew install 軟體名

// 解除安裝:
brew uninstall 軟體名

// 更新 Homebrew:
brew update 

// 檢視 Homebrew 配置資訊:
brew config 

// 檢視包列表
brew list

// 檢視包詳情
brew info 軟體名

// 檢視brew版本
brew -v

// 檢視幫助資訊
brew -h

注:使用官方指令碼同樣會遇到uninstall地址無法訪問問題,可以替換為下面指令碼:

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"

解除安裝Homebrew

cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew



參考:https://www.cnblogs.com/aaronthon/p/15601485.html