安装 ruby-oci8 gem 时遇到问题

Trouble installing ruby-oci8 gem

我正在尝试在 rails 上安装 gem ruby-oci8

我收到以下错误,

$ gem 安装 ruby-oci8

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

    current directory: /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8
/home/solovievga/.rvm/rubies/ruby-2.4.2/bin/ruby -r ./siteconf20180213-21757-1hli0rl.rb 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 sys/types.h... 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=/home/solovievga/.rvm/rubies/ruby-2.4.2/bin/$(RUBY_BASE_NAME)
        --with-instant-client
        --without-instant-client
/home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:909:in `get_home': RuntimeError (RuntimeError)
        from /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:728:in `initialize'
        from /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:269:in `new'
        from /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:269:in `get'
        from extconf.rb:22:in `<main>'
---------------------------------------------------
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:
  /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:909:in `get_home'
  /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:728:in `initialize'
  /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:269:in `new'
  /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1/ext/oci8/oraconf.rb:269:in `get'
  extconf.rb:22:in `<main>'
---------------------------------------------------
See:
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-on-osx.md for OS X
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/report-installation-issue.md to report an issue.


To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/solovievga/.rvm/gems/ruby-2.4.2/extensions/x86_64-linux/2.4.0/ruby-oci8-2.2.5.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/solovievga/.rvm/gems/ruby-2.4.2/gems/ruby-oci8-2.2.5.1 for inspection.
Results logged to /home/solovievga/.rvm/gems/ruby-2.4.2/extensions/x86_64-linux/2.4.0/ruby-oci8-2.2.5.1/gem_make.out

我想知道如何安装 ruby-oci8 软件包?

您必须设置 LD_LIBRARY_PATH 才能安装 ruby-oci8 gem。在这里,我假设您使用的是 linux os。在您的终端上试试这个。

$ LD_LIBRARY_PATH=$ORACLE_HOME/lib
$ export LD_LIBRARY_PATH
$ gem install ruby-oci8

编辑:

如果您使用 mswin32 ruby,请改用以下命令。

gem install --platform x86-mingw32 ruby-oci8
  or
gem install --platform x64-mingw32 ruby-oci8

如果您有任何疑问或疑问,请告诉我。

快乐编码

这些步骤也将引导您完成即时客户端安装过程,只是为了提供一些背景信息。在此处下载即时和 SDK zip 文件:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

将两个文件解压缩到以下目录中作为根目录。

/opt/oracle

解压后进入instantclient_12_2目录,为libclntsh.so文件创建符号链接:

ln -s libclntsh.so.12.1 libclntsh.so

现在,根据您的 OS,您需要更新 LD_LIBRARY_PATH 位置。在 Ubuntu 中,执​​行以下操作:

sudo nano /etc/ld.so.conf.d/moreLibs.conf

并在文件中输入以下内容并保存

/opt/oracle/instantclient_12_2

现在运行以下命令:

sudo ldconfig

然后重新运行你的gem安装

gem install ruby-oci8

这个解决方案对我有用

在执行 bundle install 之前,运行 在控制台的代码下方或将其添加到 bash 和源。

Export OCI_DIR=/opt/oracle/instantclient_12_2

这里 /opt/oracle/instantclient_12_2 是我 mac 机器上的 instantclient 的路径。

您需要从 instantclient 下载 https://www.oracle.com/database/technologies/instant-client/downloads.html 将下载解压到 /opt/oracle 目录并导出 OCI_DIR 环境变量。

我在安装 ruby-oci8 gem 时遇到了类似的问题。就我而言,已经有一个应用程序在使用它。当我在捆绑包安装期间使用相同的 gem 部署另一个应用程序时,发生了此错误。它要求 LD_LIBRARY_PATH 环境变量。显然,旧应用程序的安装程序没有将变量设置为持久化。

我想应该在服务器某处有一个oracle库,所以我搜索了一下。它不在 /opt 中,而是在 /usr/lib 中。我将变量设置为 /usr/lib/oracle/11.1/client64/lib 然后 gem 就顺利安装了。