Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Install ruby-oci8 on Ubuntu 12.04LTS

I execute

$ bundle install

For my rails application... (3.2.8)

Right when it gets to 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.

I did everything from about every site and forum (especially from here). This one I feel like was the closest... http://jigyasamakkar.com/ruby-oci8-with-rails-3-1-on-ubuntu/

What is the best way to solve this issue?

like image 354
harmonickey Avatar asked Jul 18 '13 00:07

harmonickey


2 Answers

I recently had to install oracle + ruby gem, here are the instructions for mac (but would work just as well for ubuntu). Full Instructions are at:

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

The key is that the ruby-oci gem needs to know where the dynamic libraries are stored. For ubuntu you need to set: LD_LIBRARY_PATH

Grab the following files:

  • 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

Extract them and put them somewhere, and then add the following environment variables. See link for detailed instructions.

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

Explanation of environment variables:

ORACLE_BASE: Where all the files are stored ORACLE_HOME: The path to the actual client LD_LIBRARY_PATH: Should point the the lib directory, make sure you have the SDK zip file extracted here TNS_ADMIN: where to find your TNS_ADMIN file (not really necessary for ruby-oci gem)

like image 106
ismail Avatar answered Nov 15 '22 01:11

ismail


For ruby-oci8 to work it is important to install the instant client, instant client SDK and the sqlplus instant client while we're at it. It's a good tool to have :)

The best resource I could find online (works like a charm) is from help.ubuntu.com so a good authoritative resource:

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

It uses rpms to install the instant client which can be done through alien. Anyway it's all explained in there.

To get the OCI to connect in your code, configure a TNS_ADMIN environment variable. I put it in the same place mentioned in the ubuntu community solution (in the same spot where ORACLE_HOME is configured). I use the same folder standard as what's usually found with oracle rdbms: network/admin.

Which for me was: 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

Then put your tnsnames.ora inside TNS_ADMIN folder.

Once that is done, just install the gem.

The gem WILL throw some errors/warning but they are not very important and it still works. Restart your session to get the environment variables.

like image 3
Nicolas de Fontenay Avatar answered Nov 15 '22 03:11

Nicolas de Fontenay