sqlite3-rubyのインストールでエラー

3年くらい前にローカルで使うために作ったRailsアプリを動かそうとして、bundle installしたら、sqlite3-rubyだけインストールできない。

見覚えがあるエラー。

gem install sqlite3-ruby
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
	ERROR: Failed to build gem native extension.

/Users/brainstorm/.rvm/rubies/ruby-1.8.7-head/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/brainstorm/.rvm/rubies/ruby-1.8.7-head/bin/ruby
	--with-sqlite3-dir
	--without-sqlite3-dir
	--with-sqlite3-include
	--without-sqlite3-include=${sqlite3-dir}/include
	--with-sqlite3-lib
	--without-sqlite3-lib=${sqlite3-dir}/lib
	--enable-local
	--disable-local


Gem files will remain installed in /Users/brainstorm/.rvm/gems/ruby-1.8.7-head@rails3/gems/sqlite3-1.3.8 for inspection.
Results logged to /Users/brainstorm/.rvm/gems/ruby-1.8.7-head@rails3/gems/sqlite3-1.3.8/ext/sqlite3/gem_make.out


2010年の2月に同じエラーを見ているけど、このときはdebian。 今回はmac
sqlite3-rubyのインストール - brainstorm


いろいろググった結果、xcodeでインストールされるgccがよくないということがわかった。
参考 : MacOSX LionでのRubyの扱い方、またはllvm-gccについて。 - 南極の図書館

以下、同じ事態に遭遇したときのためのメモ

# brewでgccいれるための準備
brew tap Homebrew/homebrew-versions
# brewでgccのインストール
brew install gcc48
# brewでsqlite3のインストール
brew install sqlite3
# 環境変数を設定
export CC=/usr/local/bin/gcc-4.8
# rvmでrubyを入れなおす
rvm install ruby-1.8.7-head
# 必要に応じてgemsetを作成
$ rvm gemset create ******
$ rvm gemset use ******
# sqlite3-rubyのインストール
$ gem install sqlite3-ruby