Its been sometime I have been working with Ruby and Rails. It was more of Ruby and less of Rails until now. We are building a restful service in rails that would be called by Java. It was this opportunity that made me look at The Rails Way by Obie Fernandez. I must admit I got caught right from the beginning. I am in the second chapter now and the author knows what he is talking about. I would not recommend this book for a person who is starting on Rails but this is a keeper for any Rails reference. (thats what I think so far). I took a glance at the part where he talks about nginx. Not much on that either. I think it would be best to use “Agile Web Development with Rails” to begin with, this book as a reference and Ezra’s book for deployment. (my two cents).

The part that I like most in the introduction is where Obie mentions the problems being faced in enterprise software development (Legacy Systems, Business Analysts, resistant managers, politics). There are two solutions to these problems. The first is to play safe and the second is an alternative to the first one. Here is what he says —

That alternative is being exceptional ! It starts with productivity. I am talking about being so obviously effective at your job that nobody will ever be able to scapegoat you, to the extent that it would be political suicide to try.

The first two chapters talk about configuration and controllers. Each part in that chapter has some information that is new to me. Not being an expert in Ruby and Rails has made me jump back and forth between this book and the ones from Pragmatic Programmers. But, so far I have enjoyed reading it.

Having fixed the problem with the KVM switch on my machine I proceed to get my Ruby scripts working on Ubuntu. Installing Ruby and getting Rails is a breeze. The problem starts when I need to install ruby-oci8. You cannot get this by doing a gem install….need to download the tar.gz file and run the setup. I try to use tar -xvf ruby-oci8-1.0.0.tar.gz but it fails. (some problem with the header of the file). I then use gzip and tar commands separately and it works.

To install ruby-oci8 you can either do this

make install

or do this

ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

When I try them, both fail. Looking at the error I see that I need to configure ORACLE_HOME (in case of Oracle) or need to configure LD_LIBRARY_PATH (in case of Oracle Instant Client). I know that I don’t have them on my machine so I proceed to get the Oracle Instant Client. I read some blogs (see References) and find that I need the and packages. I download them and unzip them at this location /opt/oracle/instantclient (need to sudo). Having done that I set my LD_LIBRARY_PATH to /opt/oracle/instantclient.


I then proceed to create two symlinks

ln -s
ln -s

Note: In the above case, the names would depend on the version of the instant client that you have.

I go back to try out the ruby-oci8 setup and it fails again. Back to square one and I seem to have run out of ideas. A friend suggests me to check if the instant client works properly by installing sqlplus and connecting to the database. I go ahead with that (I would need sqlplus anyways).
I get the file from here. Unzip it to the location /opt/oracle/instantclient. I now go ahead and set the environment variables through the command line. (I have the LD_LIBRARY_PATH set already) and add my tnsnames.ora file to the same location.

export SQLPATH
export TNS_ADMIN

I try this command at the command line now. (where the username , password and tnsnames have appropriate variables)

sqlplus username/password@tnsname

I get this now:

sqlplus: error while loading shared libraries: cannot open shared object file: No such file or directory

What the !! Now what is this supposed to be?? I read more and run these commands:

ldd sqlplus
strace sqlplus

The first command gives me a list of library dependencies that sqlplus requires and the second command (strace) gives me a trace of system calls and signals. (see man pages of the command for details). Both indicate that a library (libaio) is missing. I run the following command :

sudo apt-get install libaio-dev

Now when I try to run sqlplus I get this error:

SQL*Plus: Release - Production on Fri Dec 21 12:57:36 2007

Copyright (c) 1982, 2007, Oracle. All rights reserved.

ORA-12154: TNS:could not resolve the connect identifier specified

At least I am close. Hmmm…problem with the tnsnames. Soon, I find that I had set TNSADMIN instead of TNS_ADMIN. sqlplus runs once i correct that. So, I can now connect to the database and am sure that the instantclient is installed correctly. Back to ruby-oci8 now.
Running the setup gives me the same problem. This time however I notice that the instantclient is recognized but there is this error (I guess the instantclient was not the problem after all …doh !!)

checking for cc... ---------------------------------------------------
error messages:
Permission denied - mkmf.log

I see that mkmf.log exists in the oci8 dir structure and has root privileges. So, I need to run the setup as root. But since all the environment variables are set on my login the setup complains that it does not see LD_LIBRARY_PATH. I go ahead and add all environment variables to /etc/profile. For global environment variables in Ubuntu see this. I restart my shell and run the following.

sudo -i
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

Success. oci8 now installs without complaints. I try my ruby scripts and everything looks good. The fruit of persistence is definitely sweet.

UPDATES: I was helping a friend install oci8 on his machine when we faced some more hurdles. Adding them here:

1. mkmf not found: You will need the development version of Ruby. sudo apt-get install ruby1.8-dev
2. Make sure you install 32 bit versions and not 64 bit ones.
3. If you see this error : “ cannot open shared object file:”, you are missing the instantclient path. Somehow adding the path in /etc/profile did not get picked up in our case. We had to add it in the .bashrc file. Make sure you open a new terminal after the changes.
4. If you have problems running ruby setup, install etc (see the last step above), check to see if you have the build-essential package installed: sudo apt-get install build-essential


Technorati Tags: , , , , , , , , , , ,

Powered by ScribeFire.