Setup ruby (oci8, sequel) for Oracle on ubuntu 14.04

Download and install Oracle instant client

  • go to http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
  • choose your environment
    • be aware that not all environments are update, for instance “Linux AMD64” is not, whereas “Linux X86-64” is
  • accept the license agreement
  • download the necessary rpm files (not the zip archives) (you may be prompted to login with your Oracle account)
    • Instant Client Package – Basic
      • oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
    • Instant Client Package – SQL*Plus
      • oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
    • Instant Client Package – SDK
      • oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
  • install alien to be able to install the rpm’s
    • sudo apt-get install alien
  • install the rpms using alien
    • sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
    • sudo alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
    • sudo alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

Make libraries available

  • sudo touch /etc/ld.so.conf.d/oracle.conf && sudo vi /etc/ld.so.conf.d/oracle.conf
  • add the following
    • /usr/lib/oracle/12.1/client64/lib
  • sudo ldconfig

Make headers available

As the original ubuntu guide indicates, some libraries expect the headers to reside below the main oracle home directory.

  • sudo ln -s /usr/include/oracle/12.1/client64 /usr/lib/oracle/12.1/client64/include

Setup ORACLE_HOME

  • sudo touch /etc/profile.d/oracle.sh && sudo vi /etc/profile.d/oracle.sh
  • add the following lines
    • export NLS_LANG=”AMERICAN_AMERICA.UTF8″
    • export ORACLE_HOME=/usr/lib/oracle/12.1/client64
    • export PATH=$PATH:$ORACLE_HOME/bin

SSH tunnel into your oracle box

Probably you don’t want to expose the necessary ports on your oracle box to the outside (not even to your development box) . So just quick recap of how to tunnel the needed port using ssh.

  • ssh -L 1521:localhost:1521 your_oracle_box

Install necessary gems

  • gem install ruby-oci8
  • gem install sequel

You may also want to install other gems like activerecord-oracle_enhanced-adapter.

Test the whole setup

Run the following in irb to check, if everything works as expected. This expects that there is a schema some with a table named table.

require "oci8"
require "sequel"

DB = Sequel.oracle("your_sid", user: "your_user”, password: "your_password", host: "localhost", port: 1521)

puts DB["select * from some.table"].count

 

Setup ruby (oci8, sequel) for Oracle on ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s