23

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
Jonathan Soifer
  • 2,715
  • 6
  • 27
  • 50
earlyriser
  • 419
  • 1
  • 5
  • 13

12 Answers12

47

Slightly updated version of install of ruby-oci8 for 10.9/10.10/10.11OSX Mavericks/Yosemite/El Capitan - step-by-step:

  1. Go here: http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
  2. Download the 64bit versions of instantclient-sqlplus, instantclient-sdk, instantclient-basic - the 32bit versions do not work with OSX 10.9
  3. Create directories at /opt/oracle
  4. Unzip instantclient-basic first, move to /opt/oracle (should add a folder - something like /opt/oracle/instantclient_11_2/)
  5. Unzip instantclient-sdk and move its contents to /opt/oracle/instantclient_11_2/
  6. Unzip instantclient-sqlplus and move its contents /opt/oracle/instantclient_11_2/
  7. Open Terminal (if you haven't already) and type...
  8. DYLD_LIBRARY_PATH=/opt/oracle/instantclient_11_2 export DYLD_LIBRARY_PATH
  9. ORACLE_HOME=/opt/oracle/instantclient_11_2 export ORACLE_HOME
  10. cd /opt/oracle/instantclient_11_2
  11. ln -s libclntsh.dylib.11.1 libclntsh.dylib (creates a symbolic link)
  12. env
  13. verify that DYLD_LIBRARY_PATH=/opt/oracle/instantclient_11_2 (be sure there's no trailing / after instantclient_11_2)
  14. verify ORACLE_HOME=/opt/oracle/instantclient_11_2
  15. gem install ruby-oci8

Should work after that. The file structure should look similar to this:

enter image description here

Laurel
  • 5,965
  • 14
  • 31
  • 57
etusm
  • 4,082
  • 1
  • 30
  • 26
  • 18
    Wow, pain in the ass! – Rn2dy May 13 '14 at 05:57
  • 1
    At first, the instructions looked daunting but I followed them step by step and was finally able to install ruby-oci8 on Yosemite. Great job writing them up. Thanks so much. – trivektor Oct 29 '14 at 08:46
  • Hey, quick question. How to find the system password: `Please provide the SYSTEM password for your Oracle installation` – tmartin314 Nov 24 '14 at 18:27
  • Thank you for saving my sanity! Also, for Mavericks (10.9.5) I needed to set the ARCHFLAGS environment variable before install could succeed: ARCHFLAGS="-arch x86_64" – Jeff Dec 09 '14 at 17:53
  • 6
    On El Capitan, the DYLD_* environment variables are ignored, so the gem won't build. [This script](https://github.com/kubo/fix_oralib_osx) fixes the problem. – timseal Nov 17 '15 at 16:11
  • 4
    In the newer releases, meaning with SIP ie. where users are not able to set DYLD_LIBRARY_PATH, one should use specific OCI_DIR instead. – Mieszko Jan 27 '18 at 06:22
9

For anyone attempting to get this to work in the good old year of 2016, the error message now contains a link to the page http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-on-osx.md that gives you instructions for how to do it using Homebrew. None of the above stuff worked for me (and I tried it all), but then I took this problem to a coworker and they said, "Hey, did you try that link in the error message there?" Sure enough, that did it.

Garrett Disco
  • 670
  • 1
  • 9
  • 27
  • just checking, but by following those instructions you got it to install with the 12.1.0.2 instaclient versions on El Capitan? – J Set Jun 08 '16 at 13:58
  • El Capitan yes, 12.1.0.2... Not sure, and I don't have access to the machine that I set this up on the first time. Pretty sure it was the most recent version as of last March, whatever that was. – Garrett Disco Jun 23 '16 at 22:13
3

On OS X Sierra, I was unable to set DYLD_LIBRARY_PATH due to system integrity protection (https://forums.developer.apple.com/thread/13161), so I copied all oracle's instant client files to /users/.../lib, since it has a fallback to some directories including this one:

...
checking the default value of DYLD_FALLBACK_LIBRARY_PATH...
checking /Users/<username>/lib... no
checking /usr/local/lib... no
checking /lib... no
checking /usr/lib... no
...

And the gem installed successfully!

cp -R /opt/oracle/instantclient_11_2/* /users/..username../lib
gem install ruby-oci8

Building native extensions.  This could take a while...
Successfully installed ruby-oci8-2.2.2
1 gem installed
Jose Neto
  • 85
  • 9
  • While in `~`, I created a symlink: `ln -s /usr/local/oracle/instantclient_18_1/ lib`, then installed the gem: `gem install ruby-oci8`. This worked for OS X Mojave. – craig Mar 01 '19 at 15:48
2

In case anyone else needs to install a legacy version of ruby-oci8 on Ruby 1.8.7 on mac osx el capitan, I had success installing ruby-oci8-2.1.2 using the following method. I think it will also work on other ruby-1.8.7 versions as well (ruby-oci8 < 2.2.0) but I haven't checked other versions:

  1. Go here: http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html Download the 64bit versions of instantclient-basic, instantclient-sdk, instantclient-sqlplus (I'm using the -macos.x64-11.2.0.4.0 versions)
  2. Copy the zip files to /opt/oracle and unzip each of them. It should extract them to /opt/oracle/instantclient_11_2
  3. cd /opt/oracle/instantclient_11_2
  4. ln -s libclntsh.dylib.11.1 libclntsh.dylib
  5. curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb
  6. Be sure to append the -a flag when running the script, this will make the script fix the libs using an absolute path rather than an @rpath/*.dylib path which ends up choking the gem build process. (read the fix_oralib.rb script first if you want to check). Anyways, run: ruby fix_oralib.rb -a
  7. export OCI_DIR=/opt/oracle/instantclient_11_2
  8. Now grab the ruby-oci8 source git clone https://github.com/kubo/ruby-oci8.git
  9. Checkout the version you want to install (I needed 2.1.2) git checkout ruby-oci8-2.1.2
  10. Edit this file: ruby-oci8/ext/oci8/oraconf.rb and change this line:

when /darwin/ @@ld_envs = %w[DYLD_LIBRARY_PATH] so_ext = 'dylib'

To this:

when /darwin/ @@ld_envs = %w[DYLD_LIBRARY_PATH OCI_DIR] so_ext = 'dylib'

  1. Now change back into the root directory of the gem itself and build the gemspec: gem build ruby-oci8.gemspec
  2. 2potatocakes$ gem install ruby-oci8-2.1.2.gem Building native extensions. This could take a while... Successfully installed ruby-oci8-2.1.2 1 gem installed
2potatocakes
  • 2,240
  • 15
  • 20
2

If you are using MAC with El Capitan, the DYLD_* environment variables are ignored,due the latest embedded feature of System Integrity Protection (SIP).

SO if you wants to install ruby-oci8 with El Capitan, first you have to disable SIP.

Follow these steps to disable SIP:

  1. Restart your Mac.
  2. Before OS X starts up, hold down Command-R and keep it held down until you see an Apple icon and a progress bar. Release. This boots you into Recovery.
  3. From the Utilities menu, select Terminal.
  4. At the prompt type exactly the following and then press Return: csrutil disable
  5. Terminal should display a message that SIP was disabled.
  6. From the  menu, select Restart.

If you still facing problem try this link http://blog.codiez.co.za/2013/09/setup-oracle-instant-client-ruby-oci8-gem-mac/

1

The error message is somewhat verbose, but it basically says that you need to install the Oracle Client libraries and point the DYLD_LIBRARY_PATH variable to that location.

Steen
  • 6,573
  • 3
  • 39
  • 56
  • Hi Steen. What you said was the problem, however I choose the other answer because it fits the way I asked the question, but you nailed the problem. – earlyriser Jun 23 '14 at 13:29
1

Begin by downloading oracle instantclient version 11.2 for 32 bit Linux from their website. Version 12 or later will not work with some databases (I always grabbed the .zip versions, so that's what the guide assumes. It also assumes the downloaded files are in the /tmp folder.). You will need the basic version, sqlplus, and sdk. Once those downloads are completed, execute the following commands in the terminal

sudo mkdir -p /opt/oracle
sudo cd /opt/oracle
sudo unzip /tmp/instantclient-basic-linux-11.2.0.4.0.zip
sudo unzip /tmp/instantclient-sqlplus-linux-11.2.0.4.0.zip
sudo unzip /tmp/instantclient-sdk-linux-11.2.0.4.0.zip
sudo apt-get install libaio1
sudo cd instantclient_11_2
sudo ln -s libclntsh.so.11.2 libclntsh.so

-Now, we'll need to tell our bash shell where the oracle client is located. So allow yourself to see hidden files, and open up $home/.bashrc with a text editor. Add the following line to the bottom of the file and then save it:

export LD_LIBRARY_PATH=/opt/oracle/instantclient_11_2

-Now source .bashrc to load the new settings with this command in the terminal:

source ~/.bashrc

-Now if we did everything correctly, we should be able to install the oracle database adapter gem. Try it with this command:

gem install ruby-oci8 -v '2.1.5'
Justin
  • 143
  • 2
  • 13
1

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
Caleb
  • 3,692
  • 3
  • 24
  • 28
0

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.

bvk48
  • 21
  • 5
  • You are supposed to follow the guide using the latest release available. I can assure you it works just used it to install 19_8 – N Djel Okoye Jun 30 '21 at 09:45
0

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'
fcce
  • 1,034
  • 1
  • 12
  • 24
0

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  
N Djel Okoye
  • 950
  • 12
  • 10
-1

If you are using OS X El Capitan, Yosemite and Mavericks. You should use Instant Client 12.1.0.2 Download Instant Client 12.1.0.2 from oracle website

  1. instantclient-basic-macos.x64-12.1.0.2.0.zip
  2. instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
  3. instantclient-sdk-macos.x64-12.1.0.2.0.zip

Then follow these steps :-

  1. Create directories at /opt/oracle
  2. Unzip instantclient-basic first, move to /opt/oracle (should add a folder -
    something like /opt/oracle/instantclient_12_1/)
  3. Unzip instantclient-sdk and move its contents to /opt/oracle/instantclient_12_1/
  4. Unzip instantclient-sqlplus and move its contents /opt/oracle/instantclient_12_1/
  5. Open Terminal (if you haven't already) and type...

DYLD_LIBRARY_PATH=/opt/oracle/instantclient_12_1 export DYLD_LIBRARY_PATH ORACLE_HOME=/opt/oracle/instantclient_12_1 export ORACLE_HOME

  1. cd /opt/oracle/instantclient_12_1

ln -s libclntsh.dylib.12.1 libclntsh.dylib (creates a symbolic link)

ln -s libocci.dylib.12.1 libocci.dylib

  1. run: env
    1. verify that DYLD_LIBRARY_PATH=/opt/oracle/instantclient_11_2 (be sure there's
      no trailing / after instantclient_11_2) verify ORACLE_HOME=/opt/oracle/instantclient_11_2
    2. gem install ruby-oci8 -v gemVersion

Note:- If this still didn't work fro you try disabling SIP on your mac then try it again.

It has worked for me hope it works for you too. All the best

user2918410
  • 119
  • 1
  • 1
  • 5