Setup Oracle Instant Client and Ruby Oci8 Gem on Mac
Recently i have had to get my dev environment setup to connect to oracle for a project.
Getting the client setup can sometimes be a real pain with a Mac. Oracle does provide client libraries but they are painfully slow in updating them and fixing bugs. There was an outstanding segmentation fault bug for over 2 years.
Here are the steps to get it setup on Mac, and it would probably work for ubuntu etc, just have not tested it.
Which will add the environment variables to your .bash_profile, You can also find this in my dotfiles
Test Sql*Plus works
123456789101112
sqlplus user/pass@orademo
SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 12 09:19:55 2013
Copyright (c) 1982, 2012, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select table_name from user_tables;
You could also store multiple versions of the client, with different .oracle_client files, with a small shell script you could switch between different versions (i.e like when oracle does not fix a bug for 2 years! )
Install Ruby oci gem
123456
cd /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib
ln -s libclntsh.dylib.11.1 libclntsh.dylib
ln -s libocci.dylib.11.1 libocci.dylib
# Make sure sdk directory is in /usr/local/oracle/product/instantclient_64/11.2.0.3.0/libgem install ruby-oci8
Test that it works…
12345678
irbirb(main):001:0>require'oci8'irb(main):006:0>o=OCI8.new('user','pass','127.0.0.1/orademo')=>#<OCI8:user>irb(main):011:0>o.exec('select * from dual')do|r|putsr.join(',');endX=>1irb(main):012:0>exit
If you have issues connecting with an SID or Service Name, try using the IP.
You now have a working oracle database client, and can connect to it from ruby.