参考文档
oralce instantclient x86_64 11.2.0.3.0 已经发布了,可以直接用64位。
* rvm get stable #升级rvm
* 下载并安装oralce instantclient,可参考 http://ronr.blogspot.com/2013/02/oracle-client-11gr2-11203-for-apple-mac.html
* 需要安装client sqlplus sdk缺一不可
* gem install ruby-oci8
development:
adapter: oracle_enhanced
database: //localhost:1521/xe
username: user
password: secret
或者development: adapter: oracle_enhanced host: localhost port: 1521 database: xe username: user password: secret
development:
adapter: oracle_enhanced
database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))"
username: user
password: secret
在rails 4.0.0 下,使用
gem 'activerecord-oracle_enhanced-adapter'
会出现 错误:
undefined method `arel_attributes_values' for class
解决方案
change
gem 'activerecord-oracle_enhanced-adapter'
to
gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/yahonda/oracle-enhanced.git', branch: 'rails4'
and bundle update
. And that should do it.
设置环境变量
#vi ~/.bash_profile
LD_LIBRARY_PATH="/opt/oracle/instantclient_12_1"
export LD_LIBRARY_PATH
export ORACLE_HOME=$LD_LIBRARY_PATH
TNS_ADMIN=/opt/oracle/tns
export TNS_ADMIN
export NLS_LANG="AMERICAN_AMERICA.UTF8"
PATH=$PATH:$ORACLE_HOME
http://ruby-oci8.rubyforge.org/en/
Introduction
This page explains the way to install ruby-oci8 for Oracle Instant Client.
For Oracle Full Client, look at Install for Oracle Full Client. For Windows, look at Install Binary Package unless you have a special need to compile ruby-oci8 by yourself.
Install Oracle Instant Client Packages
Donwload Instant Client Packages
Download the following packages from Oracle Technology Network.
- Instant Client Package - Basic or Basic Lite
- Instant Client Package - SDK
- Instant Client Package - SQL*Plus
Note: use 32-bit packages for 32-bit ruby even though the OS is 64-bit.
UNIX zip packages
Unzip the packages as follows:
mkdir /opt
mkdir /opt/oracle
cd /opt/oracle
unzip path/to/instantclient-basic-OS-VERSION.zip
unzip path/to/instantclient-sdk-OS-VERSION.zip
unzip path/to/instantclient-sqlplus-OS-VERSION.zip
If /opt/oracle/instantclient10_1/libclntsh.so is not found, make a symbolic link to link the library.
cd /opt/oracle/instantclient10_1
ln -s libclntsh.so.10.1 libclntsh.so
Note:
- use libclntsh.sl instead of libclntsh.so on HP-UX PA-RISC.
- use libclntsh.dylib instead of libclntsh.so on Mac OS X.
- skip this step for AIX.
Set the library search path, whose name depends on the OS, to point to the installed directory.
OS | library search path |
---|---|
Linux | LD_LIBRARY_PATH |
Solaris 32-bit ruby | LD_LIBRARY_PATH_32 or LD_LIBRARY_PATH |
Solaris 64-bit ruby | LD_LIBRARY_PATH_64 or LD_LIBRARY_PATH |
HP-UX PA-RISC 32-bit ruby | SHLIB_PATH |
HP-UX PA-RISC 64-bit ruby | LD_LIBRARY_PATH |
HP-UX IA64 | LD_LIBRARY_PATH |
Mac OS X | DYLD_LIBRARY_PATH |
AIX | LIBPATH |
For example: $ LDLIBRARYPATH=/opt/oracle/instantclient102 $ export LDLIBRARYPATH
Linux rpm packages
Install the downloaded packages as follows:
rpm -i path/to/oracle-instantclient-basic-VERSION-ARCH.rpm
rpm -i path/to/oracle-instantclient-devel-VERSION-ARCH.rpm
rpm -i path/to/oracle-instantclient-sqlplus-VERSION-ARCH.rpm
Set LDLIBRARYPATH to point to the directory where libclntsh.so is installed.
For example: $ LDLIBRARYPATH=/usr/lib/oracle/10.2.0.3/client/lib $ export LDLIBRARYPATH
Windows
Unzip the packages and set PATH to point to the directory where OCI.DLL is installed.
Check the environment
Oracle installation
Run the following command and confirm it works fine. If it doesn't work well, check LD_LIBRARY_PATH or PATH.
sqlplus USERNAME/PASSWORD
ruby installation
Run the following command. If it ends with "can't find header files for ruby" or "ruby: no such file to load -- mkmf (LoadError)", you need to install ruby-devel(redhat) or ruby-dev(debian/ubuntu).
ruby -r mkmf -e ""
development tools
You need a C compiler and development tools such as make or nmake. Note that they must be same with ones used to compile the ruby. For example, you need Oracle Solaris Studio, not gcc, for ruby compiled by Oracle Solaris Studio.
Installation
If you get a problem in the following steps, look at Platform Specific Issues and Report Installation Issues.
gem package
Run the following command.
gem install ruby-oci8
If you get a problem, look at Platform Specific Issues and Report Installation Issues.
tar.gz package
Download the source code
Download the latest tar.gz package such as ruby-oci8 2.1.0.tar.gz, which is the latest version at the time of writing, from rubyforge.
Note: if you are using Windows and you have no special need to compile it by yourself, look at install-binary-packge.
Run make and install
UNIX or Windows(mingw32, cygwin)
gzip -dc ruby-oci8-VERSION.tar.gz | tar xvf -
cd ruby-oci8-VERSION
make
make install
note: If you use 'sudo
', use it only when running 'make install
'. 'sudo
' doesn't pass library search path to the executing command for security reasons.
Windows(mswin32)
gzip -dc ruby-oci8-VERSION.tar.gz | tar xvf -
cd ruby-oci8-VERSION
nmake
nmake install