Rails Note #12: Oracle on Intel Mac
-
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.
- 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 |
- Make a symbolic link
cd /Library/Oracle/instantclient/10.2.0.4 ln -s libclntsh.dylib.10.1 libclntsh.dylib |
- 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) ) ) |
- Install the oracle-adapter for rails
sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org |
- 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
- 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.