So first things first, get a copy of Ubuntu, install it, and then update the packages as the OS tells you to do. Once you have a fresh OS, we will install Ruby and friends from the command line using apt-get (though you could probably just as soon use the Synaptic Package Manager GUI).
Install Ruby & Friends
Installing Ruby, Rails, and RubyGems is a relatively straight forward affair and can be done with apt-get commands. The following was taken from this tutorial and may be redundant but is included here for completeness. There is also a nice thread on this on TxD. So lets get to it.
Install the GCC compilers and developer tools.
$ sudo apt-get install build-essential
Now we’ll install Ruby and friends. In this command, I am including version numbers which may not be necessary (see this thread).
$ sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8
Next we need to make some symlinks for basic Ruby commands (assuming that you installed using the method above).
$ sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
$ sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
$ sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
$ sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb
Install RubyGems
$ wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
$ tar xvzf rubygems*
$ cd rubygems*
$ ruby setup.rb
Now you are all set to install Rails and Mongrel (which I adore for use as a development server).
$ sudo gem install rails
$ sudo gem install mongrel
Now that we have Ruby and Rails installed, let's take a look at getting an Oracle client on our fresh Ubuntu installation.
Oracle Clients for Ubuntu
Information regarding an appropriate Oracle client for use with 10g databases is somewhat scant, especially with regards to Rails. But read on, an Oracle client that works with Rails is available for Ubuntu from the package manager!
In order to get Rails to talk to an Oracle database, you must have two things installed. 1) You must install an Oracle client and 2) You must install the Ruby OCI8 driver. It seems that the OCI8 driver piggybacks on top of the functionality of the Oracle client - at least on Linuxm, but the assumption is that it functions the same on Windows.
Among the clients apparently able to connect to a 10g database are the Oracle 10g client (full installation), Oracle Instant Client, and to my suprise (and my DBA's), the Oracle Express Edition (XE) Client. The installation that I was able to get working was using the Express Edition, but these instructions should also work with the full client install (though that seems to be an extremely complicated option at the present moment). I'm afraid you are on your own with the Instant Client, though it should not be that had once you understand what is involved.
While you can download the .deb package directly from Oracle, for Ubuntu, I recommend using the Synaptic Package Manager included in the Ubuntu installation to get the Oracle packages. The first thing you will need to do is add the repository to the file /etc/apt/sources.list. Simply add the following line to the bottom of the file and save it.
deb http://oss.oracle.com/debian unstable main non-free
The package "oracle-xe-client" should now appear in the package listing. Mark it for installation and apply the changes. This should install the XE client. In my experience, this was placed in /usr/lib/oracle/. This path will be important for environment variables.
Setting Environment Variables
Now that you have the Oracle XE client successfully installed, you need to make sure your environment variables are set so that the Ruby OCI8 install scripts can find the necessary files. I had problems getting the local ~/.bash_profile file to load at all on Ubuntu, and it seems this is not unusual. I have been too lazy to track down the cause of this or its solution, so I modified the /etc/profile instead (you must be root user). So these are the variables that you should set:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client
export TNS_ADMIN=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME/bin:$PATH
export NLS_LANG=$ORACLE_HOME/bin/nls_lang.sh
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export SQL_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/lib
Another thing to note about using Oracle is that you must have a file called "tnsnames.ora" somewhere it can be found ($ORACLE_HOME). Chances are if you are reading this, you are talking to a DBA who has this file for you. Mine had one for me. This file tells your client where the databases are.
Install Ruby OCI8
Get your copy of Ruby OCI8, decompress it, and read the README. Follow the instructions for the "Full Client Install". There are only 3 steps and it basically boils down to doing a make; make install;.
While this sounds trivial, it is definitely not. On Ubuntu this is the most tedious part of the entire process. Oracle is a monster. There are dozens of things that need to be in place before the OCI8 driver will complile correctly (see the previous section), including environment variables and above all, a complete installation of the client. I mention this because while trying to install the Ruby OCI 8 driver on Red Hat with a partial client install (I dont know why it was like this... "enterprise") I got nothing but errors. So make sure that you have the development files that are included with the full install (like oci.h!).
When you finish, its worth checking the installation by firing up the irb and typing:
> require "oci8"
=> true
If you get "false" as a response, something has gone wrong in the installation and you should try again.
Configure Rails
Now all thats left to do is to configure Rails. To use Oracle from within Rails, you should have your "database.yml" file setup correctly. My file looks something like this:
development:
adapter: oci
host: hostname
username: username
password: password
Conclusion
This post is assuredly incomplete. For the moment, this is intended to document my process of installing Ubuntu and using Rails with an Oracle database from scratch. If you try this as well, please post a comment or two.
Next time I will post the long promised lib file for executing Oracle stored procedures in Rails.