libclntsh.so.12.1 : cannot open shared object file error when running sample of node-oracledb

My first suspicion would be that LD_LIBRARY_PATH is not actually set or exported correctly. Triple-check it is set and the directory is readable by the actual shell that attempts to start node.

export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2

You need to do this in any shell that starts Node.js.

I'd also check what other Oracle libraries are installed on the machine and make sure you don't have clashes.

Using ldconfig to set the path globally will almost certainly be easier than setting LD_LIBRARY_PATH. You can do something like:

sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

See the Instant Client install instructions for details.

If you have optional Net configuration files like sqlnet.ora or tnsnames.ora, they can be put in a directory /opt/oracle/instantclient_12_2/network/admin which is a default location for configuration files. See Optional Oracle Net Configuration.

Update: if you install the Instant Client 19.3 RPM packages, the ldconfig step is automatically done. (You still need/could/should do it for a 19.3 ZIP file install)

Instant Client 19 will connect to Oracle Database 11.2 or later, so use Instant Client 19 unless you have a special requirement for an older version.


export works only for one process. It seems, it doesn't present at your terminal window (it is separate process). So, you should execute following again before starting node connect.js (in the same terminal window where you going to start node):

export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH