CentOSでRuby環境を作る
Ruby
# yum install ruby
RubyGems
標準リポジトリに無いので、リポジトリの追加を行う必要がある。
# vi /etc/yum.repos.d/dlutter.repo
[dlutter] name=Unsupported RHEL5 packages (dlutter) baseurl=http://people.redhat.com/dlutter/yum/rhel/5/$basearch/ enabled=0 gpgcheck=0
# yum --enablerepo=dlutter install rubygems.noarch
...
TMail
# gem install tmail Bulk updating Gem source index for: http://gems.rubyforge.org Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError) ERROR: Failed to build gem native extension. ruby extconf.rb install tmail can't find header files for ruby. Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/gem_make.out
普通にインストールしようとすると失敗する。
ruby-develが無いからっぽいので、ruby-develを先に入れてみる。
# yum install ruby-devel
...
# gem install tmail Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError) ERROR: Failed to build gem native extension. ruby extconf.rb install tmail creating Makefile make gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fno-strict-aliasing -fPIC -D_FILE_OFFSET_BITS=64 -c tmailscanner.c make: gcc: コマンドが見つかりませんでした make: *** [tmailscanner.o] エラー 127 Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/gem_make.out
まだ失敗する。gccも入っていないっぽい。
# gem install tmail
...
今度は成功した。
MySQL/Ruby
# gem install mysql Select which gem to install for your platform (x86_64-linux) 1. mysql 2.7.3 (mswin32) 2. mysql 2.7.1 (mswin32) 3. mysql 2.7 (ruby) 4. mysql 2.6 (ruby) 5. Skip this gem 6. Cancel installation > 3 Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError) ERROR: Failed to build gem native extension. ruby extconf.rb install mysql 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... no 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=/usr/bin/ruby --with-mysql-config --without-mysql-config --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib --without-mysqlclientlib --with-mlib --without-mlib --with-mysqlclientlib --without-mysqlclientlib --with-zlib --without-zlib --with-mysqlclientlib --without-mysqlclientlib --with-socketlib --without-socketlib --with-mysqlclientlib --without-mysqlclientlib --with-nsllib --without-nsllib --with-mysqlclientlib --without-mysqlclientlib Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
失敗する。mysql-develが無いからかもしれないので先に入れる。
(もしかすると必要ないかも)
# yum install mysql-devel
...
# gem install mysql
...
同じエラーで、失敗する。
どうも、オプションが足りないみたい。
# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config Select which gem to install for your platform (x86_64-linux) 1. mysql 2.7.3 (mswin32) 2. mysql 2.7.1 (mswin32) 3. mysql 2.7 (ruby) 4. mysql 2.6 (ruby) 5. Skip this gem 6. Cancel installation > 3 Building native extensions. This could take a while... Successfully installed mysql-2.7
今度はうまくいった。
動作確認
# irb irb(main):001:0> require 'dbi' => true irb(main):002:0> dbh = DBI.connect('dbi:mysql:test:localhost', 'root', 'root') irb(main):003:0> dbh.select_one('select version()') => ["5.0.45"] irb(main):004:0> exit