Homebrew 是一个 Mac OS X 下的软件包管理工具。既然已经有了MacPorts 和 Fink,那么为什么还要制造新的轮子呢?

1. Homebrew的安装、卸载与更新

Refer to https://github.com/mxcl/homebrew/wiki/Installation

1.1. Requirements

1.2. Install

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 202201, done.
remote: Compressing objects: 100% (54549/54549), done.
remote: Total 202201 (delta 146509), reused 202141 (delta 146467)
Receiving objects: 100% (202201/202201), 42.19 MiB | 31.00 KiB/s, done.
Resolving deltas: 100% (146509/146509), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 0049b1a mercurial: update 3.1.2 bottle.
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started

1.3. Uninstall

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Before Install Available check is : 33,455M,after is 33,415M

/usr/local size from 22M to 50M

1.4. Update

Fetch the newest version of Homebrew from GitHub using git

brew --version

brew update
Updated Homebrew from 32723234 to 32726535.

brew --version

2. Homebrew的使用

2.1. System Structure

ll /usr/local/
Cellar/         # download pkg, can hold multiple version
Library/        #
├── Aliases     #
├── ENV/        # xcode compile tools
├── Formula/    # pkg install config, such as nginx.rb
bin/            # commands
etc/            # configurations
opt/            # current version: mysql@ -> ../Cellar/mysql/5.6.10

2.2. 软件管理

2.2.1. 查看已经安装的软件(list)

brew list

2.2.2. 搜索需要的软件并安装(search&install)

$ brew search rar
gnu-scientific-library     unrar
$ brew install unrar

2.3. Problem Solve


## error info
curl: (56) Recv failure: Operation timed out
Error: Download failed: https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

brew edit gd
#  url 'https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz'
  url 'http://fossies.org/linux/www/libgd-2.1.0.tar.gz'
brew install gd

2.4. Check Status

$ brew doctor
Warning: Your compilers are different from the standard versions for your Xcode.
If you have Xcode 4.3 or newer, you should install the Command Line Tools for
Xcode from within Xcode's Download preferences.
Otherwise, you should reinstall Xcode.

Install Command Line Tools in Xcode

brew doctor
Your system is raring to brew.

3. Homebrew的使用经验

3.1. brew help

##  --build-from-source
brew install NAME  # install software by name
brew doctor        #Troubleshooting

3.2. nginx config

Change Compile info:

#vi /usr/local/Library/Formula/nginx.rb brew edit nginx

  def install                                
    args = ["--prefix=#{prefix}",            
            "--with-http_stub_status_module", # add here

sudo nginx -s stop
brew uninstall nginx
brew install nginx
sudo nginx
curl http://localhost/status

Nginx Config:

user  liyan admin;

make auto run service

cp /usr/local/Cellar/nginx/1.2.7/homebrew.mxcl.nginx.plist /srv/www/moin/etc/
# vi .plist and remove user info
# To have launchd start nginx at login with root right(port at 80):
ln -sfv /srv/www/moin/etc/homebrew.mxcl.nginx.plist /System/Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# Load nginx manually:
sudo launchctl load /System/Library/LaunchDaemons/homebrew.mxcl.nginx.plist

4. Reference

CategoryMac_OS_X CategoryTool