软件包管理工具Homebrew

Mac OS X是基于Unix的操作系统, Homebrew可以安装大部分为Unix/Linux开发的软件。
Homebrew - macOS 不可或缺的套件管理器

安装

Mac OS X自带Ruby,打开命令行Terminal,输入ruby --versionruby -v查看Ruby版本

1
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin16]

打开命令行Terminal,输入

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

执行完成即可安装成功。

查看版本和帮助信息

打开命令行Terminal,输入brew --versionbrew -v查看brew版本:Homebrew 1.1.11
打开命令行Terminal,输入brewbrew help查看brew帮助信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Example usage:
brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
Troubleshooting:
brew config
brew doctor
brew install -vd FORMULA
Developers:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
http://docs.brew.sh/Formula-Cookbook.html
Further help:
man brew
brew help [COMMAND]
brew home

使用方法

搜索

安装前不确定或者记不全软件的名字,使用brew search [TEXT|/REGEX/]来进行搜索

1
2
3
$ brew search /wge*/
flowgrind libmowgli rawgl wget ✔
liblwgeom pwgen sf-pwgen wgetpaste

安装&卸载

安装和卸载一个软件,命令分别是brew install wget
brew uninstall wget

1
2
3
4
5
6
7
8
$ brew install wget
==> Downloading https://homebrew.bintray.com/bottles/wget-1.19.1.sierra.bottle.t
Already downloaded: /Users/sun/Library/Caches/Homebrew/wget-1.19.1.sierra.bottle.tar.gz
==> Pouring wget-1.19.1.sierra.bottle.tar.gz
🍺 /usr/local/Cellar/wget/1.19.1: 10 files, 1.6MB
$ brew uninstall wget
Uninstalling /usr/local/Cellar/wget/1.19.1... (10 files, 1.6MB)

说明:Homebrew 会将软件安装到独立目录(/usr/local/Cellar/),并将文件软链接至/usr/local,所以无需担心 Homebrew 的安装位置。

隐藏命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
brew services
brew services
Easily start and stop formulae via launchctl
Integrates Homebrew formulae with OS X's launchctl manager. Services can be
added to either /Library/LaunchDaemons or ~/Library/LaunchAgents.
Basically, items in /Library/LaunchDaemons are started at boot, while those
in ~/Library/LaunchAgents are started at login.
When started with sudo, it operates on /Library/LaunchDaemons; otherwise,
it operates on ~/Library/LaunchAgents.
On start the plist file is generated and written to a Tempfile, and then
copied to the launch path (existing plists are overwritten).
[sudo] brew services list
List all running services for the current user (or root)
[sudo] brew services run formula|--all
Run the service formula without starting at login (or boot).
[sudo] brew services start formula|--all
Install and start the service formula at login (or boot).
[sudo] brew services stop formula|--all
Stop the service formula after it was launched at login (or boot).
[sudo] brew services restart formula|--all
Stop (if necessary), install and start the service formula at login (or boot).
[sudo] brew services cleanup
Remove all unused services.

其他命令

  • brew list 列出已安装的软件

  • brew update 更新Homebrew

  • brew upgarde 更新所有package

  • brew home 用浏览器打开Homebrew的官方网站

  • brew info 显示软件信息

  • brew deps 显示包依赖

  • brew server 启动web服务器,可以通过浏览器访问http://localhost:4567/ 来同网页来管理包