X

The leading edge of scripting languages and Oracle Database brought to you by the Data Access Development team

Installing node-oracledb on OS X with Oracle Instant Client 11.2.0.4

Christopher Jones
Senior Principal Product Manager

----> This note and script is obsolete. The current node-oracledb OS X install instructions contain nicer solutions <----- .

I've been hacking an Apple OS X shell script to install node-oracledb. You tell it where your Instant Client libraries and headers ZIP packages are. It then installs node-oracledb, resulting in an instantclient directory and a node_modules directory. This automates the instructions Node-oracledb Installation on OS X with Instant Client.

My osxinstall.sh script can be seen here. [Now removed]

I was investigating how to avoid needing to set DYLD_LIBRARY_PATH. I wanted to find how to replicate the use of rpath, which is available for node-oracledb on Linux. A standard install on OS X needs DYLD_LIBRARY_PATH set, otherwise Node.js will fail with the error:

cjones@cjones-mac:~/n$ node select1.js
/Users/cjones/n/node_modules/oracledb/lib/oracledb.js:28
throw err;

^
Error: dlopen(/Users/cjones/n/node_modules/oracledb/build/Release/oracledb.node, 1):
Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
Referenced from: /Users/cjones/n/node_modules/oracledb/build/Release/oracledb.node
Reason: image not found
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/cjones/n/node_modules/oracledb/lib/oracledb.js:23:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

So, I was playing with osxinstall.sh to see how to circumvent this. Before running osxinstall.sh, edit it and set the paths to where the Instant Client 11.2.0.4 'basic' and 'sdk' ZIP files are located on your filesystem, see IC_BASIC_ZIP and IC_SDK_ZIP. (You can download Instant Client from OTN. Use the 64-bit packages). You also specify the target application directory you are using, see TARGET_DIR. This is where the components are installed into. Update https_proxy if you are behind a firewall, otherwise comment it out.

If you have various node_modules directories around, then npm might end up installing oracledb in an unexpected place and the script will error.

The key bit of osxinstall.sh that I was interested in is:

    # For Oracle Instant Client 11.2.0.4: these are the default paths we will change
IC_DEF1=/ade/b/3071542110/oracle/rdbms/lib
IC_DEF2=/ade/dosulliv_ldapmac/oracle/ldap/lib
. . .
# Warning: work in progress - may not be optimal
chmod 755 $OCI_LIB_DIR/*dylib $OCI_LIB_DIR/*dylib.11.1
install_name_tool -id libclntsh.dylib.11.1 $OCI_LIB_DIR/libclntsh.dylib.11.1
install_name_tool -change $IC_DEF2/libnnz11.dylib $OCI_LIB_DIR/libnnz11.dylib \
$OCI_LIB_DIR/libclntsh.dylib.11.1
install_name_tool -id libnnz11.dylib $OCI_LIB_DIR/libnnz11.dylib
install_name_tool -change $IC_DEF1/libclntsh.dylib.11.1 \
$OCI_LIB_DIR/libclntsh.dylib.11.1 $OCI_LIB_DIR/libociei.dylib
install_name_tool -change $IC_DEF1/libclntsh.dylib.11.1 \
$OCI_LIB_DIR/libclntsh.dylib.11.1 $NODE_ORACLEDB_LIB
chmod 555 $OCI_LIB_DIR/*dylib $OCI_LIB_DIR/*dylib.11.1

This changes the library install and identification names using install_name_tool. Note this tool cannot allocate more space for path names than currently exists. My code is a work in progress; I may work out a better way, perhaps using libtool. Comments & suggestions welcome.

The script does more than most people probably need. In future even I might only run parts extracted from it.

If you are new to node-oracledb, check out its install and API documentation on GitHub. You may also be interested in reading The Easiest Way to Install Oracle Database on Mac OS X.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.