ruby-oci8をインストールしてみる step3
gemをソースからインストール済みとする。
[root@cent5-64b-40 ruby]# gem list --local *** LOCAL GEMS *** [root@cent5-64b-40 ruby]# [root@cent5-64b-40 ruby]# gem update --system Updating rubygems-update Fetching: rubygems-update-1.8.11.gem (100%) Successfully installed rubygems-update-1.8.11 Installing RubyGems 1.8.11 RubyGems 1.8.11 installed == 1.8.11 / 2011-10-03 * Bug fix: * Deprecate was moved to Gem::Deprecate to stop polluting the top-level namespace. ------------------------------------------------------------------------------ RubyGems installed the following executables: /usr/local/bin/gem RubyGems system software updated [root@cent5-64b-40 ruby]#
ここから本番
[root@cent5-64b-40 html]# gem install ruby-oci8 Building native extensions. This could take a while... ERROR: Error installing ruby-oci8: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking for load library path... LD_LIBRARY_PATH is not set. checking ld.so.conf... no checking for cc... ok checking for gcc... yes checking for LP64... yes checking for ruby header... ok *** 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/local/bin/ruby --with-instant-client --without-instant-client ./oraconf.rb:924:in `get_home': RuntimeError (RuntimeError) from ./oraconf.rb:711:in `initialize' from ./oraconf.rb:345:in `new' from ./oraconf.rb:345:in `get' from extconf.rb:18 --------------------------------------------------- Error Message: Set the environment variable ORACLE_HOME if Oracle Full Client. Append the path of Oracle client libraries to LD_LIBRARY_PATH if Oracle Instant Client. Backtrace: ./oraconf.rb:924:in `get_home' ./oraconf.rb:711:in `initialize' ./oraconf.rb:345:in `new' ./oraconf.rb:345:in `get' extconf.rb:18 --------------------------------------------------- See: * http://ruby-oci8.rubyforge.org/ja/HowToInstall.html * http://ruby-oci8.rubyforge.org/ja/ReportInstallProblem.html Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/ruby-oci8-2.0.6 for inspection. Results logged to /usr/local/lib/ruby/gems/1.8/gems/ruby-oci8-2.0.6/ext/oci8/gem_make.out [root@cent5-64b-40 html]#
あらら、エラー吐いてもうたよ
ORACLE_HOME環境変数がいるの?
oracleのbash_profileから借用して設定してみます。
[root@cent5-64b-40 html]# cat /home/oracle/.bash .bash_history .bash_logout .bash_profile .bashrc [root@cent5-64b-40 html]# cat /home/oracle/.bash_profile | grep ORACLE export ORACLE_BASE=/opt/oracle/app export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/dbhome_1 export PATH=${PATH}:${ORACLE_HOME}/bin [root@cent5-64b-40 html]# export ORACLE_BASE=/opt/oracle/app [root@cent5-64b-40 html]# export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/dbhome_1 [root@cent5-64b-40 html]# echo $ORACLE_HOME /opt/oracle/app/product/11.2.0/dbhome_1 [root@cent5-64b-40 html]# set -o vi [root@cent5-64b-40 html]# gem install ruby-oci8Building native extensions. This could take a while... Successfully installed ruby-oci8-2.0.6 1 gem installed Installing ri documentation for ruby-oci8-2.0.6... Installing RDoc documentation for ruby-oci8-2.0.6... [root@cent5-64b-40 html]#
まずはgemのインストールはうまくいったみたい
[root@cent5-64b-40 html]# gem list --local *** LOCAL GEMS *** rdtool (0.6.29) rttool (1.0.3.0) ruby-oci8 (2.0.6) rubygems-update (1.8.11) [root@cent5-64b-40 html]#
つぎはoracle userになって、sqlplusの動作の確認
[oracle@cent5-64b-40 ~]$ sqlplus sys/XXXXXX@YYYY as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 5 23:14:57 2011 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning and Real Application Testing options SQL> SQL> select count(*) from user_tables; COUNT(*) ---------- 941 SQL>
ここまでは、まぁ順調。
今日はねむいから明日にするw
おやすみぃ
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
というわけで次の日になりました。
次のようにするとうごきますな
[oracle@cent5-64b-40 ~]$ cat orcl_conn2.rb require 'oci8' my_ora = OCI8.new("user", "pass", "orcl") my_ora.exec("select * from table where record='0001'") do |r| puts r.join(',') end [oracle@cent5-64b-40 ~]$ ruby -I /usr/local/lib/ruby/gems/1.8/gems/ruby-oci8-2.0.6/lib ./orcl_conn2.rb
gemのライブラリパスは、gemが面倒みてくれるとおもったんだけど、自分でなんとか
しないといけないらしい。
ちなみに -I オプションを指定しないとつぎのようなエラーになる。
[oracle@cent5-64b-40 ~]$ ruby ./orcl_conn2.rb ./orcl_conn2.rb:1:in `require': no such file to load -- oci8 (LoadError) from ./orcl_conn2.rb:1 [oracle@cent5-64b-40 ~]$