[轉載]mac下homebrew的使用

 

該文轉自:https://www.zybuluo.com/phper/note/87055php

mac系統也是基於unix的系統,因此也繼承類不少unix的特性,包括軟件的編譯,安裝等。ubuntu下有快捷命令apt-get install來快速安裝軟件。centos下有yum install來快速安裝。因此,mac下也有一種方式,就是使用brewhtml

brew是Mac下的一個包管理工具,它從下載源碼解壓而後 ./configure && make install ,同時會包含相關依存庫。並自動配置好各類環境變量,並且很是易於卸載。 這個對程序員來講簡直是福音,簡單的指令,就能快速安裝和升級本地的各類開發環境。node

home brew 官網是 http://brew.sh/index_zh-cn.htmlnginx

 

安裝brew

打開 itrem 。輸入一條命令便可安裝好 brew。git

 
  1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

這樣一個簡單的命令,咱們就安裝好來brew 。來驗證一下,輸入brew命令:程序員

 
  1. Example usage:
  2. brew [info | home | options ] [FORMULA...]
  3. brew install FORMULA...
  4. brew uninstall FORMULA...
  5. brew search [foo]
  6. brew list [FORMULA...]
  7. brew update
  8. brew upgrade [FORMULA...]
  9. brew pin/unpin [FORMULA...]
  10. Troubleshooting:
  11. brew doctor
  12. brew install -vd FORMULA
  13. brew [--env | config]
  14. Brewing:
  15. brew create [URL [--no-fetch]]
  16. brew edit [FORMULA...]
  17. open https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
  18. Further help:
  19. man brew
  20. brew home

出現了不少幫助命令,說明咱們已經安裝成功了。github

 

用brew 安裝源碼

安裝好了brew以後,咱們就能夠用這個命令安裝各類源碼了。好比安裝一下wget工具。這個工具能在命令行中幫咱們下載各類數據。chrome

 
  1. brew install wget

這樣一個簡單的命令就能夠了。它會幫咱們下載好wget,而且編譯執行安裝,還會下載各類依賴包,設置好各類配置和參數。ubuntu

安裝好的 wget 會被安裝到/usr/local/Cellar/wget/下。而且將wget命令軟連接至 /usr/local/bin 目錄下。這樣全局就均可以使用wget命令了。centos

咱們一樣可使用brew安裝好git,node,openssl,svn等各類。

安裝好的這些軟件都會統一安裝到/usr/local/Cellar/目錄下,統一管理。並且安裝目錄代碼會被同步到/usr/local/opt/下,任何的增刪改都會保持這2個目錄的同步。而且已經軟鏈好各類命令到/usr/local/bin下。

咱們去看看:

 
  1. ls -l /usr/loal/bin
  2. -rwxr-xr-x 1 yangyi admin 791 3 26 17:47 brew
  3. lrwxr-xr-x 1 yangyi admin 30 3 27 13:34 node -> ../Cellar/node/0.12.1/bin/node
  4. lrwxr-xr-x 1 yangyi admin 30 4 14 15:16 wget -> ../Cellar/wget/1.16.3/bin/wget

/usr/local/Cellar 和 /usr/local/opt/ 同步,增刪改都會同步。

 
  1. $ ls /usr/local/opt
  2. brew-cask nginx node openssl pcre pkg-config wget xz
  3. $ ls /usr/local/Cellar/
  4. brew-cask nginx node openssl pcre pkg-config wget xz

ps: 那我就搞不懂了,那爲啥wget -> ../Cellar/wget/1.16.3/bin/wget 命令映射要映射到Cellar目錄,而不是opt目錄呢?

 

brew 的經常使用命令

經常使用的命令沒幾個:

 
  1. brew install wget # 安裝源碼
  2. brew info svn # 顯示軟件的各類信息,包括版本啊源碼地址啊等等
  3. brew uninstall wget # 卸載軟件,很爽,一鍵靜默卸載
  4. brew search git # 模糊搜索brew 支持的軟件。若是不加軟件名,就會列出全部它支持的軟件。多的很。
  5. brew list # 列出本機經過brew安裝的全部軟件
  6. brew update # 跟新brew軟件自身
  7. brew upgrade wget # 更新安裝過的軟件,若是不加軟件名,就更新全部能夠更新的軟件
  8. brew cleanup # 清除下載的各類緩存
 

brew cask

brew cask 是在brew 的基礎上一個加強的工具,用來安裝Mac上的Gui程序應用包(.dmg/.pkg), 好比qq、chrome、xun lei等。它先下載解壓到統一的目錄中(/opt/homebrew-cask/Caskroom),省掉了本身去下載、解壓、拖拽(安裝)等蛋疼步驟,一樣,卸載至關容易與乾淨。而後再軟鏈到~/Applications/目錄下, 一鼓作氣。很是方便,並且還包含不少在 AppStore 裏沒有的經常使用軟件。

是否是很牛逼啊!!!

brew cask的官網是:http://caskroom.io

github地址是:https://github.com/caskroom/homebrew-cask

 

brew cask 的安裝

也一樣是一條命令搞定,前提是已經安裝了brew:

brew install caskroom/cask/brew-cask

這樣一條命令久搞定來brew cask 的安裝,是否是很爽。

brew cask help一下看安裝成功沒?也是出現各類命令和幫助手冊:

 
  1. $ brew cask
  2. brew-cask provides a friendly homebrew-style CLI workflow for the
  3. administration of Mac applications distributed as binaries.
  4. Commands:
  5. alfred displays note about new built-in alfred support
  6. audit verifies installability of Casks
  7. cat dump raw source of the given Cask to the standard output
  8. cleanup cleans up cached downloads and tracker symlinks
  9. create creates the given Cask and opens it in an editor
  10. doctor checks for configuration issues
  11. edit edits the given Cask
  12. fetch downloads Cask resources to local cache
  13. home opens the homepage of the given Cask
  14. info displays information about the given Cask
  15. install installs the given Cask
  16. list with no args, lists installed Casks; given installed Casks, lists staged files
  17. search searches all known Casks
  18. uninstall uninstalls the given Cask
  19. update a synonym for 'brew update'
  20. zap zaps all files associated with the given Cask
  21. See also "man brew-cask"

好,咱們來來下一個iTerm來看看:

 
  1. brew cask install iTerm

簡單的2條命令就能夠了,很是之快,它會講軟件安裝到/opt/homebrew-cask/Caskroom目錄下,而且軟鏈到~/Applications了,這樣就能在應用程序裏找到它。就能方便的使用。

 
  1. $ cd /opt/homebrew-cask/Caskroom/
  2. $ ls
  3. iterm2

咱們剛纔的iTerm了。

再看看軟鏈,用戶本身手動下載安裝的App會被安裝到~/Applications,進這個目錄看看:

 
  1. $ cd ~/Applications/
  2. $ ls -l
  3. total 8
  4. drwxr-xr-x 3 yangyi staff 102 4 8 22:27 GitHub.app
  5. lrwxr-xr-x 1 yangyi staff 48 3 27 16:58 iTerm.app -> /opt/homebrew-cask/Caskroom/iterm2/2.0/iTerm.app

看到了吧。咱們剛纔的iTerm就軟鏈到了統一的安裝目錄。

 

brew cask 經常使用命令

下面說一些經常使用到的各類命令。

 
  1. brew cask install qq # 下載安裝軟件
  2. brew cask uninstall qq # 卸載軟件
  3. brew cask search qq # 模糊搜索軟件,若是不加軟件名,就列出全部它支持的軟件
  4. brew cask info qq # 顯示這個軟件的詳細信息,若是已經用cask安裝了,也會顯示其安裝目錄信息等
  5. brew cask list # 列出本機按照過的軟件列表
  6. brew cask cleanup # 清除下載的緩存以及各類連接信息
  7. brew update && brew upgrade brew-cask # 更新cask自身

或許你已經注意到了,好像並無提供更新用cask安裝軟件命令啊。的確是沒有。是的。目前 homebrew-cask 並無命令直接更新全部已安裝的軟件,軟件更新主要是經過軟件自身的更新流程,不過也能夠經過如下所示命令先刪除 APP,再從新安裝。

brew cask uninstall APP && brew cask install APP

軟件一樣也會安裝到/opt/homebrew-cask/Caskroom目錄下。

over

參考資料: 
http://ljhero.info/2013-08-17/homebrew-cask.html 
http://www.udpwork.com/item/11775.html 
http://www.zhihu.com/question/22624898

相關文章
相關標籤/搜索