Mac OS X(Lion)にHomebrewをインストール

前提:Xcodeがインストールされていること。

1. GithubからrubyスクリプトでHomebrewをインストール


$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/Formula/...
/usr/local/Library/Homebrew/...

Press enter to continue
==> /usr/bin/sudo /bin/mkdir /usr/local
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> Downloading and Installing Homebrew...
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
$ brew doctor

brew doctorでエラーがないことを確認してから続けること。自分の環境ではMacportsを削除していない、Gitの設定が残っているといったエラーが出たので、両方とも削除した。

2. Gitをインストール


$ brew install git
==> Downloading http://git-core.googlecode.com/files/git-1.7.10.4.tar.gz
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/git/1.7.10.4 CC=/usr/bin/llvm-gcc CFLAGS=-Os -w
==> make CC=/usr/bin/llvm-gcc CFLAGS=-Os -w -pipe -march=core2 -msse4 LDFLAGS=
==> make clean
==> Downloading http://git-core.googlecode.com/files/git-manpages-1.7.10.4.tar.gz
######################################################################## 100.0%
==> Downloading http://git-core.googlecode.com/files/git-htmldocs-1.7.10.4.tar.gz
######################################################################## 100.0%
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d

The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
/usr/local/share/git-core/contrib
==> Summary
/usr/local/Cellar/git/1.7.10.4: 1173 files, 23M, built in 41 seconds

完了後、バージョンを確認

$ brew list -version
git 1.7.10.4

3. Homebrewの最新化


$ brew update
Initialized empty Git repository in /usr/local/.git/
remote: Counting objects: 69653, done.
remote: Compressing objects: 100% (34945/34945), done.
remote: Total 69653 (delta 46673), reused 54606 (delta 33910)
Receiving objects: 100% (69653/69653), 9.97 MiB | 1.85 MiB/s, done.
Resolving deltas: 100% (46673/46673), done.
From https://github.com/mxcl/homebrew
* [new branch] gh-pages -> origin/gh-pages
* [new branch] master -> origin/master
HEAD is now at 57449d2 the_silver_searcher 0.7.2
Already up-to-date.

4. .bash_profileにパスを通す


$ vi .bash_profile
export PATH=/usr/local/bin:$PATH
$ cat .bash_profile
export PATH=/usr/local/bin:$PATH