#前提
MacOS 10.9.4にて
$ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
$gem --version
2.3.0
#homebrewでポスグレをインストール
とりあえずhomebrewを使ってbrew install postgresql
でポスグレをインストールしておく。
brew install postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.3.5.mavericks.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.mavericks.bottle.tar.gz
==> Pouring postgresql-9.3.5.mavericks.bottle.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/issue/2510
To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
http://www.postgresql.org/docs/9.3/static/upgrading.html
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
==> Summary
? /usr/local/Cellar/postgresql/9.3.5: 2927 files, 38M
#gem install pg でGemをインストール
gem install pg
を試す。怒られた。
$sudo gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
--without-pg-config
--with-pg_config
--without-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}/
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/pg-0.17.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/pg-0.17.1/gem_make.out
pg_config
がねえとか言われてる。pg_config
ってなんだよ。ポスグレの設定っぽいけど。っと思ったら下記にあった。
/usr/local/Cellar/postgresql/9.3.5/bin/pg_config
上記の怒られ文に
If building fails, please try again with --with-pg-config=/path/to/pg_config
とあるので、下記で試す。
gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5/bin/pg_config
いけえぇぇー!!
sudo gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5/bin/pg_config
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --with-pg-config=/usr/local/Cellar/postgresql/9.3.5/bin/pg_config
なんでやねん。どう考えてもあってるだろ。
homebrewでポスグレをインストールしたときのメッセージに下記のようにあったので、ARCHFLAGを指定してgemのインストールを試みる。
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
sudo 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 3 seconds
1 gem installed
できた。なんのこっちゃ。