Rails console gets exception when loading oci8. Rake and irb work ok

I am trying to connect to an existing Oracle EX 10g database. Rake and oci seem to work, but rails console crashes.

Some stuff about my environment:

  • Centos 5.8

  • Ruby 2.0.0p481

  • Rails 4.1.6

  • Oracle Database 10g Express Edition Release 10.2.0.1.0
    Gems

  • activerecord-oracle_enhanced-adapter 1.5.5

  • ruby-oci8 2.1.7
    I have successfully run ‘rake db:schema:dump’ to get the existing schema, and can run a query in irb by requiring ‘oci8’.

Rails generate gives me almost exactly the same error…

Here’s my rails console output.

[root@BS-lite models]# rails console
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
[root@BS-lite models]# oci8lib.c:134:in oci8lib_200.so: OCI Library Initialization Error - /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/libclntsh.so.10.1 (OCIError)
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/ruby-oci8-2.1.7/lib/oci8.rb:70:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:4:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:112:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:33:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/activerecord-oracle_enhanced-adapter.rb:12:in `block in <class:OracleEnhancedRailtie>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-4.1.6/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/activerecord-4.1.6/lib/active_record/base.rb:23:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:314:in `active_record_configured?'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:248:in `disconnect_database'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:97:in `preload'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/gems/2.0.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rubystack-2.0.0-20/ruby/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

My database.yml has this under development

development:
   adapter: oracle_enhanced
database: xe
username: user****   name
password: pass****word

I don't personally know the solution but I note that googling for
OCI Library Initialization Error
yields a fair number of hits, including, for example, the fact that it
is necessary to have ORACLE_HOME defined. If it is not this then it
might be worth googling yourself and working through
the hits to see if something there is useful.

Colin