0
貌似EI Capitan和以前的版本的安装有些差别,记录一下。大体来说,你需要安装下面3个部分。
- Oracle Instant Client
- ruby-oci8 gem
- activerecord-oracle_enhanced-adapter gem
安装Oracle Instant Client
去Oracle官网下载下面几个包,并按照 http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
- instantclient-basic-macos.x64-12.1.0.2.0.zip
- instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
- instantclient-sdk-macos.x64-12.1.0.2.0.zip
解压到/opt/oracle/instantclient_12_1
cd ~
unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
unzip instantclient-sdk-macos.x64-12.1.0.2.0.zip
3. 创建link
cd /opt/oracle/instantclient_12_1
ln -s libclntsh.dylib.12.1 libclntsh.dylib
Note: OCCI programs will additionally need:
ln -s libocci.dylib.12.1 libocci.dylib
4. 配置PATH
export ORACLE_HOME=/opt/oracle/instantclient_12_1
export OCI_DIR=/opt/oracle/instantclient_12_1
export PATH=$ORACLE_HOME:$PATH
export TNS_ADMIN=$HOME
export NLS_LANG="AMERICAN_AMERICA.UTF8"
安装Gem
gem install 'ruby-oci8' -v '~> 2.1.0'
gem install 'activerecord-oracle_enhanced-adapter' -v '~> 1.5.0'
测试
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "database",
:username => "username",
:password => "password")
cursor = ActiveRecord::Base.connection.execute("SELECT 1 n FROM table")
# query data
result_data = []
result_data << cursor.column_metadata.map { |e| e.name }
while row = cursor.fetch
result_data << row
end
引用
- http://stackoverflow.com/questions/36811473/ruby-oci8-installation-error-in-mac-el-capitan
- https://craig.io/setting-up-a-rails-development-environment-with-oracle/
Post a Comment