該文轉自:https://www.zybuluo.com/phper/note/87055php
mac系統也是基於unix的系統,因此也繼承類不少unix的特性,包括軟件的編譯,安裝等。ubuntu下有快捷命令apt-get install
來快速安裝軟件。centos下有yum install
來快速安裝。因此,mac下也有一種方式,就是使用brew
。html
brew
是Mac下的一個包管理工具,它從下載源碼解壓而後 ./configure && make install
,同時會包含相關依存庫。並自動配置好各類環境變量,並且很是易於卸載。 這個對程序員來講簡直是福音,簡單的指令,就能快速安裝和升級本地的各類開發環境。node
home brew 官網是 http://brew.sh/index_zh-cn.htmlnginx
打開 itrem 。輸入一條命令便可安裝好 brew。git
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
這樣一個簡單的命令,咱們就安裝好來brew 。來驗證一下,輸入brew命令:程序員
Example usage:
brew [info | home | options ] [FORMULA...]
brew install FORMULA...
brew uninstall FORMULA...
brew search [foo]
brew list [FORMULA...]
brew update
brew upgrade [FORMULA...]
brew pin/unpin [FORMULA...]
Troubleshooting:
brew doctor
brew install -vd FORMULA
brew [--env | config]
Brewing:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
open https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
Further help:
man brew
brew home
出現了不少幫助命令,說明咱們已經安裝成功了。github
安裝好了brew以後,咱們就能夠用這個命令安裝各類源碼了。好比安裝一下wget
工具。這個工具能在命令行中幫咱們下載各類數據。chrome
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
下。
咱們去看看:
ls -l /usr/loal/bin
-rwxr-xr-x 1 yangyi admin 791 3 26 17:47 brew
lrwxr-xr-x 1 yangyi admin 30 3 27 13:34 node -> ../Cellar/node/0.12.1/bin/node
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/ 同步,增刪改都會同步。
$ ls /usr/local/opt
brew-cask nginx node openssl pcre pkg-config wget xz
$ ls /usr/local/Cellar/
brew-cask nginx node openssl pcre pkg-config wget xz
ps: 那我就搞不懂了,那爲啥wget -> ../Cellar/wget/1.16.3/bin/wget
命令映射要映射到Cellar
目錄,而不是opt
目錄呢?
經常使用的命令沒幾個:
brew install wget # 安裝源碼
brew info svn # 顯示軟件的各類信息,包括版本啊源碼地址啊等等
brew uninstall wget # 卸載軟件,很爽,一鍵靜默卸載
brew search git # 模糊搜索brew 支持的軟件。若是不加軟件名,就會列出全部它支持的軟件。多的很。
brew list # 列出本機經過brew安裝的全部軟件
brew update # 跟新brew軟件自身
brew upgrade wget # 更新安裝過的軟件,若是不加軟件名,就更新全部能夠更新的軟件
brew cleanup # 清除下載的各類緩存
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
:
brew install caskroom/cask/brew-cask
這樣一條命令久搞定來brew cask 的安裝,是否是很爽。
brew cask help
一下看安裝成功沒?也是出現各類命令和幫助手冊:
$ brew cask
brew-cask provides a friendly homebrew-style CLI workflow for the
administration of Mac applications distributed as binaries.
Commands:
alfred displays note about new built-in alfred support
audit verifies installability of Casks
cat dump raw source of the given Cask to the standard output
cleanup cleans up cached downloads and tracker symlinks
create creates the given Cask and opens it in an editor
doctor checks for configuration issues
edit edits the given Cask
fetch downloads Cask resources to local cache
home opens the homepage of the given Cask
info displays information about the given Cask
install installs the given Cask
list with no args, lists installed Casks; given installed Casks, lists staged files
search searches all known Casks
uninstall uninstalls the given Cask
update a synonym for 'brew update'
zap zaps all files associated with the given Cask
See also "man brew-cask"
好,咱們來來下一個iTerm來看看:
brew cask install iTerm
簡單的2條命令就能夠了,很是之快,它會講軟件安裝到/opt/homebrew-cask/Caskroom
目錄下,而且軟鏈到~/Applications
了,這樣就能在應用程序裏找到它。就能方便的使用。
$ cd /opt/homebrew-cask/Caskroom/
$ ls
iterm2
咱們剛纔的iTerm了。
再看看軟鏈,用戶本身手動下載安裝的App會被安裝到~/Applications
,進這個目錄看看:
$ cd ~/Applications/
$ ls -l
total 8
drwxr-xr-x 3 yangyi staff 102 4 8 22:27 GitHub.app
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 install qq # 下載安裝軟件
brew cask uninstall qq # 卸載軟件
brew cask search qq # 模糊搜索軟件,若是不加軟件名,就列出全部它支持的軟件
brew cask info qq # 顯示這個軟件的詳細信息,若是已經用cask安裝了,也會顯示其安裝目錄信息等
brew cask list # 列出本機按照過的軟件列表
brew cask cleanup # 清除下載的緩存以及各類連接信息
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