该文转自: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