2008年8月2日土曜日

[ruby] rubygems でmysql ライブラリをインストールする

mysql-develが入っているか確認する

$ rpm -qa | grep -i mysql
mysql-5.0.45-7.el5
mysql-devel-5.0.45-7.el5

gemでインストールします(そのままだとエラーが出ますね)

$ sudo /opt/ruby/bin/gem install mysql --no-rdoc --no-ri
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/opt/ruby/bin/ruby extconf.rb install mysql --no-rdoc --no-ri
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** 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=/opt/ruby/bin/ruby
--with-mysql-config
--without-mysql-config
(snip)

Gem files will remain installed in /opt/ruby/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/ruby/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

mysqlの設定を、mysql-configから取得するように指定

$ sudo /opt/ruby/bin/gem install mysql --no-rdoc --no-ri -- --with-mysql-config
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed

チェックする(require でmysqlが読み込めればOK)

$ /opt/ruby/bin/irb -rrubygems
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> exit

成功したっぽい

0 件のコメント: