Wednesday, December 06, 2006

How To Setup Ruby, Rails, and Oracle 10g on Solaris 10

Introduction



Here is the list of what you will need to have installed to run a Ruby on Rails application on Solaris 10.

* Ruby 1.8.4\+
* Oracle 10g client full install
* RubyGems
* Rails
* Mongrel
* Ruby OCI8 libraries

There are a number of dependencies in order to get these items installed which are detailed in the following sections.

This tutorial is going to assume that any Solaris machine that you are attempting installation on will be totally devoid of any software tools that would make an installation painless.

My first suggestion for this installation process is: *DO NOT use Sun's Download center*.
There is nothing simple about Sun's installations. I only tried one (gcc) and it placed the binaries in a folder that was outside of the default search path. Brilliant, thanks Sun.

Instead visit http://sunfreeware.com and search for packages for the platform in question.
In the following, I have linked to the files where possible, but in the case that you are not installing this on Solaris 10 with a Sparc processor, use the above link to get the packages.
There may be better places, but this site had all the packages I needed and better than that, it worked. If at all possible, you should be using a package manager in general, and for this, I used Sun's package manager which is pretty basic. Also, you should get the packages, NOT the src files for teh packages. If you get the src files you will need to build the packages before you install them which could be a pain. But I digress... onward!

1. Install the Oracle Client



 You \*must\* have a full install of the Oracle client for the Ruby OCI8 driver to work. This is not an option. I have gotten the OCI8 driver to compile with the Oracle Express Edition client (XE), but if at all possible, install the full client.
Check to see that you have the "oci.h" file that the Ruby OCI8 driver will want to use (which is installed with the Oracle client).


$ locate oci.h
/opt/local/oracle/product/10.2.0/client_1/rdbms/public/oci.h


This file should be somewhere like the path above - in a "public" folder.
If you do not have this file or it is in a "demo" folder, you dont have a full install of the client - stop right here and go get one installed.

1. Prerequisites



You will need to install a handful of libraries and whatnot before Ruby will work correctly.
Download these to the temporary directory of your choice.

* libiconv-1.11 (gcc dependency)
* gcc-3.4.6 or higher (requires libiconv-1.11)
* wget-1.102 not required, but it will make your life easier (requires gcc)
* openssl-0.9.8d(I have no idea why, but gem installation would not work without this package)
* readline-5.2(fixes input problem with IRB)

Also be sure that you have "make" installed. At the very least this is usually on even the most crippled system, but just check (which make).

Once you have downloaded the packages, gunzip them and install,


# pkgadd -d gcc-3.4.6-sol10-sparc-local
# pkgadd -d openssl-0.9.8d-sol10-sparc-local
# pkgadd -d wget-1.10.2-sol10-sparc-local
# pkgadd -d readline-5.2-sol10-sparc-local


or something like that...
if you want to remove the packages after installation, use pkgrm

2. Install Ruby



Download ruby-1.8.4 and install.


# wget ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/ruby-1.8.4-sol10-sparc-local.gz
# pkgadd -d ruby-1.8.4-sol10-sparc-local


Make sure everything is there ($ which ruby, $ which irb) - or better yet, fire up IRB and make sure Ruby works. Just type a few lines and exit.


$ irb
irb(main):001:0> quit


3. Install RubyGems



Congratulations, you have Ruby installed (right?). Now you will want to install RubyGems, the Ruby package manager which functions alot like Yum or MacPorts or any other intelligent package management system. On Solaris, you will need to build this from source.

Get the latest distribution of RubyGems from http://rubyforge.org/frs/?group_id=126
Or install using wget like so,


$ wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
$ tar -zxf rubygems-0.9.0.tgz
$ ruby setup.rb


Check the [reference manual|http://docs.rubygems.org/read/chapter/3] if necessary.

4. Install Ruby OCI8 driver



I cannot stress this enough: make sure you have an Oracle 10g Client installed.
If you are absolutely sure that you have it, download and gunzip/untar the source code:


$ wget http://rubyforge.org/frs/download.php/12559/ruby-oci8-0.1.16.tar.gz
$ gzip ruby-oci8-0.1.16.tar.gz | tar xvf -
$ cd ruby-oci8-0.1.16


You are now prepared to compile and install the Ruby OCI8 library.

1. Check the following:

* ruby and make (or nmake on MSVC) are in the environment variable PATH.
* sqlplus runs correctly

2. Check library search path.

If sqlplus runs correctly, the environments variables are okay in general.
But if Oracle is 64-bit and ruby is 32-bit, make sure $ORACLE_HOME/lib32
in 32-bit library search path. (LD_LIBRARY_PATH_32 on Solaris, SHLIB_PATH
on HP-UX PA-RISC.)

3. make and install


$ make
$ make install


Common sources of errors:

* Oracle client is incomplete/ cannot find oci.h
* Oracle environment variables are not set correctly
* gcc is not installed correctly or cannot be found

May the force be with you.

5. Install Rails and Mongrel



Welcome to the easy life.


$ gem install rails --include-dependencies
$ gem install mongrel --include-dependencies


Actually there is a bug in the configuration of Mongrel on Solaris that you will need to fix here.

For any Rails application, you can include the Rails libraries in the application itself so an external library in the Ruby search path is not necessary. If there is a copy of the Rails libraries, a "rails" folder, in the "vendor" folder of the Rails application you want to run, the application will use that copy of Rails instead of the gem installation. As a best practice, a copy of Rails should be included in any deployed application. The reason for this is simple: Rails changes. It is quite possible that an updated Rails gem will break your application in some unexpected way. As long as your Rails application has a checkout of Rails in its vendor folder, everything should run as expected. For more on the topic of "GemRails" and "EdgeRails", see the [Rails wiki|http://wiki.rubyonrails.com/rails/pages/EdgeRails].

No comments: