好不容易搞定了黑苹果,接下来就是 Rails 开发环境的搭建了。下面简单说说。 先吐槽一下 Oracle 对 Mac 的支持真是太弱,现在都 12c 了,11g 的 Enterprise 版的 Database 没有也就算了,连 XE 版都没有,太不算事了。难道大家都只用 Linux?Mac 可是开发的高帅富环境啊!好歹 Mac 上也是跑 Unix 内核的,就因为 MacOSX 的 server 少吗?只能装下 Instant Client 了。
入正题,先从 Oracle 网站上 download 下面几个文件(注意要和你自己的 cpu 匹配,我用 64bit 的): http://download.oracle.com/otn/mac/instantclient/11203/instantclient-basic-macos.x64-11.2.0.3.0.zip http://download.oracle.com/otn/mac/instantclient/11203/instantclient-sqlplus-macos.x64-11.2.0.3.0.zip http://download.oracle.com/otn/mac/instantclient/11203/instantclient-sdk-macos.x64-11.2.0.3.0.zip 之后启动 Terminal 到下载目录下运行(重建 InstantClient 的目录结构):
cd Downloads
unzip -qq instantclient-sqlplus-macos.x64-11.2.0.3.0.zip
unzip -qq instantclient-basic-macos.x64-11.2.0.3.0.zip
unzip -qq instantclient-sdk-macos.x64-11.2.0.3.0.zip
mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.3.0/bin
mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.3.0/lib
mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.3.0/jdbc/lib
mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.3.0/rdbms/jlib
mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.3.0/sqlplus/admin
cd instantclient_11_2
mv ojdbc* /Applications/oracle/product/instantclient_64/11.2.0.3.0/jdbc/lib/
mv x*.jar /Applications/oracle/product/instantclient_64/11.2.0.3.0/rdbms/jlib/
mv glogin.sql /Applications/oracle/product/instantclient_64/11.2.0.3.0/sqlplus/admin/
mv *dylib* /Applications/oracle/product/instantclient_64/11.2.0.3.0/lib/
mv sdk /Applications/oracle/product/instantclient_64/11.2.0.3.0/lib/
mv *README /Applications/oracle/product/instantclient_64/11.2.0.3.0/
mv * /Applications/oracle/product/instantclient_64/11.2.0.3.0/bin/
最后设置 Oracle InstantClient 的运行环境参数,运行命令:vim ~/.bash_profile,贴入以下内容:
export ORACLE_BASE=/Applications/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
export TNS_ADMIN=$ORACLE_BASE/admin/network
export NLS_LANG="AMERICAN_AMERICA.UTF8"
最后运行以下脚本安装 ruby 的 oracle 接口即可。
ln -s /Applications/oracle/product/instantclient_64/11.2.0.3.0/lib/libclntsh.dylib.11.1 /Applications/oracle/product/instantclient_64/11.2.0.3.0/lib/libclntsh.dylib
gem install ruby-oci8