7

我执行

$ 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/

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

4

2 回答 2

6

我最近不得不安装 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

获取以下文件:

  • 即时客户端-基本-linux.x64-11.2.0.3.0.zip
  • 即时客户端-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 宝石)

于 2013-09-16T08:49:43.843 回答
3

要让 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。

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

于 2013-08-02T20:54:03.603 回答