Home > mac, oracle, osx, rails, ruby > Rails Note #12: Oracle on Intel Mac

Rails Note #12: Oracle on Intel Mac

December 5th, 2008 rupert

1. Read http://www.foliosus.com/2008/05/05/connecting-ruby-on-rails-to-oracle-on-an-intel-mac-in-leopard-take-2/

2. Install Oracle Instant Client on Mac.

a. Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
- instantclient-basic-macosx-10.2.0.4.0.zip (34,020,719 bytes)

b. *Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
instantclient-sdk-macosx-10.2.0.4.0.zip (603,493 bytes)

OR download the whole bundle (10.2.0.4.zip) with sqlplus installed from my installers.

3. Put this on your sudo vim ~/.bash_profile.

export ORACLE_HOME=/Library/Oracle/instantclient/10.2.0.4
export TNS_ADMIN=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME

4. Make a symbolic link

cd /Library/Oracle/instantclient/10.2.0.4
ln -s libclntsh.dylib.10.1 libclntsh.dylib

5. Go to /Library/Oracle/instantclient/10.2.0.4 and edit tnsnames.ora. Point the Oracle SID to the IP where you installed Oracle.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.155)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )
 
 
ORCL_2_11 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )

6. Install the oracle-adapter for rails

sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org

7. In your database.yml file

development:
  adapter: oracle
  database: orcl
  username: youzhu_mobile_dev
  password: your_password

or browse the contents of a sample rails project youzhumobile.tar.gz

8. If you ever encounter an encoding problem, then we need to set the NLS_LANG environment variable before running script/server.

# export NLS_LANG=American_America.UTF8
# script/server

or I prefer setting it in the environment.rb

Rails::Initializer.run do |config|
  ENV['NLS_LANG']='American_America.UTF8'
  # Settings in config/environments/* take precedence over those specified here.

Note: If you don’t know your database encoding, then read this post.

Categories: mac, oracle, osx, rails, ruby Tags: , , ,
  1. Bobby
    December 10th, 2008 at 18:16 | #1

    For Windows:
    To install oracle_enhanced adapter
    gem install activerecord-oracle_enhanced-adapter

Comments are closed.