0
Posted on Monday, November 21, 2016 by 醉·醉·鱼 and labeled under , ,
貌似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
  1. instantclient-basic-macos.x64-12.1.0.2.0.zip
  2. instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
  3. 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

引用
  1. http://stackoverflow.com/questions/36811473/ruby-oci8-installation-error-in-mac-el-capitan
  2. https://craig.io/setting-up-a-rails-development-environment-with-oracle/
0
Responses to ... Setting up Ruby with Oracle on Mac OS El Capitan

Post a Comment