无法在Ubuntu 12.04LTS上安装ruby-oci8

时间:2013-07-18 00:21:21

标签: ruby-on-rails ruby ruby-on-rails-3 oracle

我执行

$ bundle install

对于我的rails应用程序......(3.2.8)

当它到达ruby-oci8时......

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /home/ubuntu/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb 
checking for load library path... 
  LD_LIBRARY_PATH... 
    checking /usr/lib/oracle/12.1/client/... no
  checking ld.so.conf... no
checking for cc... ok
checking for gcc... yes
checking for LP64... no
checking for sys/types.h... yes
checking for ruby header... ok
Get the version of Oracle from SQL*Plus... *** 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=/home/ubuntu/.rvm/rubies/ruby-1.9.3-p448/bin/ruby
    --with-instant-client
    --without-instant-client
/home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:760:in `get_version': RuntimeError (RuntimeError)
    from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:709:in `initialize'
    from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:320:in `new'
    from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:320:in `get'
    from extconf.rb:18:in `<main>'
---------------------------------------------------
Error Message:
  cannot get Oracle version from sqlplus
Backtrace:
  /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:760:in `get_version'
  /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:709:in `initialize'
  /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:320:in `new'
  /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/oraconf.rb:320:in `get'
  extconf.rb:18:in `<main>'
---------------------------------------------------
See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html



Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5 for inspection.
Results logged to /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/ruby-oci8-2.1.5/ext/oci8/gem_make.out

An error occurred while installing ruby-oci8 (2.1.5), and Bundler cannot continue.
Make sure that `gem install ruby-oci8 -v '2.1.5'` succeeds before bundling.

我从每个网站和论坛(尤其是来自这里)做了所有事情。我觉得这个最接近...... http://jigyasamakkar.com/ruby-oci8-with-rails-3-1-on-ubuntu/

解决此问题的最佳方法是什么?

2 个答案:

答案 0 :(得分:5)

我最近不得不安装oracle + ruby​​ gem,这里是mac的说明(但对于ubuntu也可以。)完整说明见:

http://blog.codiez.co.za/2013/09/setup-oracle-instant-client-ruby-oci8-gem-mac/

关键是ruby-oci gem需要知道动态库的存储位置。对于ubuntu,您需要设置:LD_LIBRARY_PATH

抓住以下文件:

  • instantclient-basic-linux.x64-11.2.0.3.0.zip
  • instantclient-sqlplus-linux.x64-11.2.0.3.0.zip
  • instantclient-sdk-linux.x64-11.2.0.3.0.zip

提取它们并将它们放在某处,然后添加以下环境变量。有关详细说明,请参阅链接

export ORACLE_BASE=/usr/local/oracle
export ORACLE_HOME=$ORACLE_BASE/product/instantclient_64/11.2.0.3.0
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$DYLD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_BASE/admin/network

环境变量说明:

ORACLE_BASE:存储所有文件的位置 ORACLE_HOME:实际客户端的路径 LD_LIBRARY_PATH:应该指向lib目录,确保你在这里提取了SDK zip文件 TNS_ADMIN:在哪里可以找到你的TNS_ADMIN文件(ruby-oci gem不是必需的)

答案 1 :(得分:2)

要使ruby-oci8正常工作,安装即时客户端,即时客户端SDK和sqlplus即时客户端非常重要。这是一个很好的工具:)

我能在网上找到的最好的资源(像魅力一样)来自help.ubuntu.com,所以这是一个很好的权威资源:

https://help.ubuntu.com/community/Oracle%20Instant%20Client

它使用rpms安装即时客户端,可以通过外星人来完成。无论如何,这里都有解释。

要在代码中连接OCI,请配置TNS_ADMIN环境变量。我将它放在ubuntu社区解决方案中提到的相同位置(在配置ORACLE_HOME的同一位置)。我使用与oracle rdbms中常见的文件夹标准相同的文件:network / admin。

对我来说是: sudo vi /etc/profile.d/oracle.sh export ORACLE_HOME = / usr / lib / oracle / 11.1.0.1 / client export TNS_ADMIN = / usr / lib / oracle / network / admin

然后将你的tnsnames.ora放在TNS_ADMIN文件夹中。

完成后,只需安装gem。

宝石会抛出一些错误/警告,但它们不是很重要,它仍然有效。 重新启动会话以获取环境变量。