How to setup Rails + Oracle on Ubuntu

In the beggining of the week I got myself one task: to integrate one of our customer’s rails app with another database, this time, an Oracle 10g. And I struggled to get everything up and running, after two days I finally had success, so I decided to share this valuable-ish knowledge:

First of all we need to have Oracle Instant Client’s files on our server, (you can find it here http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html), after dowload unzip them:

$ unzip path/to/instantclient-basic-OS-VERSION.zip
$ unzip path/to/instantclient-sdk-OS-VERSION.zip
$ unzip path/to/instantclient-sqlplus-OS-VERSION.zip

and move it to the proper folder:

sudo mv instantclient_12_1/ /opt/oracle/
sudo cd /opt/oracle/instantclient_12_1
$ ls -la

And check if libclntsh.so is there, if not then:

sudo ln -s libclntsh.so.12.1 libclntsh.so

Now that we got Instant Client installed we have to set the library search path, for this, put the line above in the beggining of ~/.bashrc:

LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1/

And source it:

sudo source ~/.bashrc

Because of security, our system variable LD_LIBRARY_PATH isn’t enabled when you try to install the ruby-oci8 gem, so we have to use ldconfig:

// edit:
vim /etc/ld.so.conf.d/myapp.conf

// add in the beggining of the file:
/opt/oracle/instantclient_12_1

// save and exit

//And to activate this path:
ldconfig

// to make sure you have done all correctly run:
ldconfig -v | grep oracle

// and see if your path shows up

After all that, you may be able to install the ruby-oci8 gem:

sudo gem install ruby-oci8

Everything should work now, if it still doesn’t work maybe you don’t have libaio1 installed:

 sudo apt-get install libaio1
 
10
Kudos
 
10
Kudos

Now read this

How to export your vagrant boxes

Prepare a new machine so the newcomer is able to work as soon as possible, with all the development tools your team already uses. That’s a boring task. But Vagrant came to solve that problem, making our life A LOT easier. It provides a... Continue →