How to install ruby-oci8?

Viewed 22368

I'm trying to install ruby-oci8 on OS X.

I've tried installing both with and without sudo.

Error Message without sudo:

gem install ruby-oci8
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.

Error Message with sudo:

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

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for load library path... 
  DYLD_LIBRARY_PATH is not set.
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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-instant-client
    --without-instant-client
./oraconf.rb:887:in `get_home': RuntimeError (RuntimeError)
    from ./oraconf.rb:703:in `initialize'
    from ./oraconf.rb:319:in `new'
    from ./oraconf.rb:319: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 DYLD_LIBRARY_PATH if Oracle Instant Client.

The 'sudo' command unset some environment variables for security reasons.
Pass required varialbes as follows
     sudo env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH /usr/bin/gem install ruby-oci8
  or 
     sudo env ORACLE_HOME=$ORACLE_HOME /usr/bin/gem install ruby-oci8


Backtrace:
  ./oraconf.rb:887:in `get_home'
  ./oraconf.rb:703:in `initialize'
  ./oraconf.rb:319:in `new'
  ./oraconf.rb:319:in `get'
  extconf.rb:18

See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html
12 Answers

This looked painful. I think I may have found a better way to resolve this (on Mac OS, at least).

Just run the following brew commands:

brew tap InstantClientTap/instantclient
brew install instantclient-basic
brew install instantclient-sqlplus
brew install instantclient-sdk

For some reason ruby-oci8 was not getting installed with instant client_11_2 for me. I tried all the answers suggested here and other places but couldnt get it done. Later I tried with instant client 12_1 and it worked without any issues.

updated version of install of ruby-oci8 for CENTOS7

cd /etc/yum.repos.d
sudo wget http://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
sudo rpm --import RPM-GPG-KEY-oracle-ol7
sudo yum-config-manager --enable ol7_oracle_instantclient
sudo yum install oracle-instantclient18.3-basic
sudo yum install oracle-instantclient18.3-devel
sudo yum install oracle-instantclient18.3-jdbc
sudo yum install oracle-instantclient18.3-sqlplus
export ORACLE_HOME=/usr/lib/oracle/18.3/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
gem install ruby-oci8 -v '2.2.7'

For those using zsh rather than bash still follow Etusm's answer however, on steps 8 and 9 replace with

8. export DYLD_LIBRARY_PATH=/opt/oracle/instantclient_11_2 
9. export ORACLE_HOME=/opt/oracle/instantclient_11_2  
Related