在Mac OS El Capitan上安装Oracle和ruby

貌似EI Capitan和以前的版本的安装有些差别,记录一下。大体来说,你需要安装下面3个部分。

  • Oracle Instant Client
  • ruby-oci8 gem
  • activerecord-oracle_enhanced-adapter gem

安装Oracle Instant Client

去Oracle官网下载下面几个包,并按照官方的教程操作。

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
创建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
配置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/

转载需保留链接来源:软件玩家 » 在Mac OS El Capitan上安装Oracle和ruby

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

感谢您的支持!

微信扫一扫打赏