MAC EI Capitan 下安装ruby-oci8

本来在osx下开发好好的,因为升级到EI Capitan连不上oracle数据库而报废,经过漫长的研究和查资料终于解决了这个大BUG
根本原因是新版本的系统因为安全原因不允许设置 DYLD_LIBRARY_PATH这个变量了,所以新版的ruby-oci8已经做了调整可以使用OCI_DIR解决,但是如果你想安装旧版本的就只能编译一个自己的修改版本安装了.
以下过程安装最新版本可以通过了

  • 1、下载instantclient
    http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
    到这里下载
    instantclient-basic-macos.x64-11.2.0.3.0.zip
    instantclient-sqlplus-macos.x64-11.2.0.3.0.zip
    instantclient-sdk-macos.x64-11.2.0.3.0.zip

  • 2、解压
    cd ~/Downloads
    unzip -qq instantclient-basic-macos.x64-11.2.0.4.0.zip
    unzip -qq instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
    unzip -qq instantclient-sdk-macos.x64-11.2.0.4.0.zip

  • 3、拷贝文件

    #创建文件夹--------------------------------------------
    cd instantclient_11_2
    mkdir -p /usr/local/oracle/product/instantclient_64/11.2.0.3.0/bin
    mkdir -p /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib
    mkdir -p /usr/local/oracle/product/instantclient_64/11.2.0.3.0/jdbc/lib
    mkdir -p /usr/local/oracle/product/instantclient_64/11.2.0.3.0/rdbms/jlib
    mkdir -p /usr/local/oracle/product/instantclient_64/11.2.0.3.0/sqlplus/admin
    
    #开始拷贝文件-------------------------------------------
    mv ojdbc* /usr/local/oracle/product/instantclient_64/11.2.0.3.0/jdbc/lib/
    mv x*.jar /usr/local/oracle/product/instantclient_64/11.2.0.3.0/rdbms/jlib/
    # rename glogin.sql to login.sql
    mv glogin.sql /usr/local/oracle/product/instantclient_64/11.2.0.3.0/sqlplus/admin/login.sql
    # Move lib & sdk
    mv *dylib* /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib/
    mv sdk /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib/sdk
    mv *README /usr/local/oracle/product/instantclient_64/11.2.0.3.0/
    mv * /usr/local/oracle/product/instantclient_64/11.2.0.3.0/bin/
    
    #处理文件-----------------------------------------
    cd /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib
    ln -s libclntsh.dylib.11.1 libclntsh.dylib
    ln -s libocci.dylib.11.1 libocci.dylib
    
  • 4、设置TNS
    mkdir -p /usr/local/oracle/admin/network
    touch/usr/local/oracle/admin/network/tnsnames.ora
    tnsnames.ora 内容如下

REACH =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.27)(PORT = 1521))
)
(CONNECT_DATA =(SERVICE_NAME = reach1)
)
)

  • 5、编辑.bash_profile文件,加入如下代码:
    export ORACLE_BASE=/usr/local/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/instantclient_64/11.2.0.3.0
    export PATH=$ORACLE_HOME/bin:$PATH
    export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib:$DYLD_LIBRARY_PATH
    export TNS_ADMIN=$ORACLE_BASE/admin/network
    export SQLPATH=$ORACLE_HOME/sqlplus/admin
    export OCI_DIR=/usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib
    然后执行 source ~/.bash_profile

  • 6、测试
    sqlplus user/pass@orademo

    SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 12 09:19:55 2013
    
    Copyright (c) 1982, 2012, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> select table_name from user_tables;
    
  • 7、这时候依然不能安装ruby-oci8,还需要fix_oralib.rb
    cd /usr/local/oracle/product/instantclient_64/11.2.0.3.0/lib
    curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb
    ruby fix_oralib.rb
    如果上面下载fix_oralib.rb因为权限问题失败,可下载到其他目录再拷贝过去即可
    这时候可以安装ruby-oci8了
    参考地址
    1.https://github.com/kubo/ruby-oci8/issues/89
    2.http://blog.codiez.co.za/2013/09/setup-oracle-instant-client-ruby-oci8-gem-mac/

或者可以直接修改ruby-oci8源码,将使用DYLD_LIBRARY_PATH的地方替换成OCI_DIR即可
然后自己编译一个gem文件安装也是可以解决的

你可能感兴趣的:(MAC EI Capitan 下安装ruby-oci8)