Rails:pg gemをインストールできない

Herokuにアプリケーションをアップするために、DBをPostgreSQLに変えることに。
と思ったら、pgをインストールできなかった(´・Д・)」

※DBの変更の仕方は以前のブログに書いてます。
RailsでSQLiteをやめてPostgreSQLを使う - Hello world, I am kgmx.

#Gemfile
gem 'pg', '0.17.1'
$ bundle intall

Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.11
Using json 1.8.1
Using minitest 5.4.0
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Using activesupport 4.1.4
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.4
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.1.4
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.1.4
Using activemodel 4.1.4
Using arel 5.0.1.20140414130214
Using activerecord 4.1.4
Using thor 0.19.1
Using railties 4.1.4
Using activerecord-session_store 0.1.0 from git://github.com/rails/activerecord-session_store.git (at master)
Using bcrypt 3.1.7
Using coderay 1.1.0
Using better_errors 1.1.0
Using debug_inspector 0.0.2
Using binding_of_caller 0.7.2
Using bundler 1.6.5
Using chunky_png 1.3.1
Using coffee-script-source 1.7.1
Using execjs 2.2.1
Using coffee-script 2.3.0
Using coffee-rails 4.0.1
Using fssm 0.2.10
Using sass 3.2.19
Using compass 0.12.7
Using hike 1.2.3
Using multi_json 1.10.1
Using tilt 1.4.1
Using sprockets 2.11.0
Using compass-rails 1.1.7
Using orm_adapter 0.5.0
Using warden 1.2.3
Using devise 3.2.4
Using haml 4.0.5
Using haml-rails 0.5.3
Using hashie 3.2.0
Using jbuilder 2.1.3
Using jquery-rails 3.1.1
Using method_source 0.8.2
Using newrelic_rpm 3.9.2.239
Using oauth 0.4.7
Using omniauth 1.2.2
Using omniauth-oauth 1.0.1
Using omniauth-twitter 1.0.1

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20140825-20987-1vx7pma.rb extconf.rb --with-pg-config=/usr/local/bin/pg_config
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
     --with-pg
     --without-pg
     --with-pg-config
     --with-pg-dir
     --without-pg-dir
     --with-pg-include
     --without-pg-include=${pg-dir}/include
     --with-pg-lib
     --without-pg-lib=${pg-dir}/
     --with-pqlib
     --without-pqlib
     --with-libpqlib
     --without-libpqlib
     --with-ms/libpqlib
     --without-ms/libpqlib

extconf failed, exit code 1

Gem files will remain installed in /var/folders/hm/spf_35s96v3cfvtc932bt60r0000gp/T/bundler20140825-20987-u7l8k0/pg-0.17.1/gems/pg-0.17.1 for inspection.
Results logged to /var/folders/hm/spf_35s96v3cfvtc932bt60r0000gp/T/bundler20140825-20987-u7l8k0/pg-0.17.1/extensions/universal-darwin-13/2.0.0/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

色々試してもできなかった。

$brew update
$brew uninstall
$brew install postgresql

最終的に以下でインストールできました。
理由は...わかりません。MacOS Xの問題?ちなみに今はMavericksです。

$ sudo su
sh-3.2# 
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.17.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.17.1
Installing ri documentation for pg-0.17.1
Done installing documentation for pg after 1 seconds
1 gem installed
sh-3.2#

※DBの変更の仕方は以前のブログに書いてます。(しつこい。)
RailsでSQLiteをやめてPostgreSQLを使う - Hello world, I am kgmx.