[Es] Homebrew 安裝實例 & Error處理

Homebrew 安裝實例 & Error處理

Homebrew 是 Mac OS X 缺失的軟件包的管理器;

安裝 Apple 沒有預裝 但 你需要的東西,使 Mac OS X 更完整;

使用 gem 來安裝 gems、用 brew 來安裝那些依賴包。

目錄

Step 1 安裝前的準備工作

Step 2 Install Homebrew

Step 3 brew 常用命令


Step 1 安裝前的準備工作

請先確認本地是否安裝Xcode,Terminal(終端)Xcode安裝檢查:

$ xcode-select -p 
/Applications/Xcode.app/Contents/Developer  #系統返回

⚠️ 常見問題 提前說明:

- Homebrew /usr/local 寫入權限問題

Homebrew執行brew update之類的命令時,需要對 /usr/local 進行寫入操作。由於 /usr/local 是系統文件夾,MacOS限制了對其的操作權限,使得用戶無法像對普通文件夾操作一樣,通過 chown 獲得 write 權限。

蘋果公司從 OS X El Capitan 10.11 系統開始使用了 `Rootless` 機制,可以將該機制理解爲一個更高等級的系統的內核保護措施,系統默認將會鎖定 `/system`、`/sbin`、`/usr` 這三個目錄。

  • Terminal(終端)輸入:
$ csrutil status
System Integrity Protection status: enabled.  
# Rootless默認打開狀態,此時無法通過sudo命令,對/system、/sbin、/usr 這三個目錄進行權限修改。
  • 打開/關閉 Rootless 機制
  1. 重啓 Mac;
  2. 開機時後按下 Command+R,進入恢復模式;
  3. 在上面的菜單實用工具中找到並打開 Terminal(終端) 輸入命令關閉 Rootless 機制:
$ csrutil disable
System Integrity Protection status:disabled.  #關閉狀態
  • 退出恢復模式,開啓Terminal(終端)並修改 /local 權限:
$ sudo chown -R $(whoami) /usr/local
  • 開啓 Rootless 方式同關閉方式一樣,在恢復模式的Terminal輸入:
$ csrutil enable
System Integrity Protection status: enabled.  #開啓狀態

Step 2 Install Homebrew

  • Terminal(終端)安裝 Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

⚠️ 安裝中出現提示,按 回車鍵 確認繼續安裝,按 其他鍵 退出安裝:

Press Enter to continue or any other key to abort

⚠️ Homebrew官網 安裝路徑會更新,如上述命令無效請進入官網複製安裝路徑。

⚠️ 因“網絡長城”問題會導致403報錯等問題,可更換官網嘗試:HomeBrew官網(國內版) <-詞條更新於2019.09.20

  • 安裝完成後驗證:
$ brew -v 
Homebrew 1.7.1 
Homebrew/homebrew-core (git revision e5ba; last commit 2018-07-17) 
  • brew doctor 命令檢查安裝是否存在衝突:
$ brew doctor 
Your system is ready to brew.(正常返回信息)

⚠️ 如出現以下類似的 Error 警告,請參照系統的相應提示進行解決:

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. 
If everything you use Homebrew for is working fine: 
please don't worry and just ignore them. Thanks! 

Error: Setting DYLD_LIBRARY_PATH can break dynamic linking. You should probably unset it. 

Error: Some keg-only formula are linked into the Cellar. Linking a keg-only formula, such as gettext, into the cellar with You may wish to brew unlink these brews:

Step 3 brew 常用命令

# 檢查 homebrew衝突命令 
$ brew doctor
# 幫助 命令
$ brew help
# 安裝 軟件包命令 
$ brew install
# 更新 數據包命令 
$ brew update
# 卸載 軟件包命令 
$ brew uninstall --force PACKAGE_NAME

# 清除 軟件包所有老版本 
$ brew cleanup --force -s PACKAGE_NAME

# 清除 軟件包無效的軟鏈接 
$ brew prune
# 查看 已安裝軟件包列表命令 
$ brew list

參考文獻 :

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章