Permanently Set LD_LIBRARY_PATH
I am installing OpenSSL into a custom location and I'd like to permanently set the LD_LIBRARY_PATH to /custom/opt/apache/openssl/lib, without having to set the variable, every time. I'm not a dev, I'm in ops and we need this in a custom location, for now; please forgive me for not fully understanding. I need the openssl binary in /custom/opt/apache/openssl/bin to always look for its library files in its own folder, by default, if possible. The OpenSSL binary we have custom installs lives in /custom/opt/apache/openssl/bin
Unless I set the variable, either manually or in .profile, I get the error:
/custom/opt/apache/openssl/bin $> ./openssl version
exec(): 0509-036 Cannot load program ./openssl because of the following errors:
0509-150 Dependent module /usr/lib/libssl.a(libssl64.so.3) could not be loaded.
0509-152 Member libssl64.so.3 is not found in archive
For example, without the variable, it queries the system's distro of OpenSSL:
$> openssl version -a
OpenSSL 3.0.10 1 Aug 2023 (Library: OpenSSL 3.0.10 1 Aug 2023)
built on: Tue Jan 16 12:13:04 2024 UTC
platform: aix-xlc_r
options: bn(64,32)
compiler: xlc_r -qpic -q32 -qmaxmem=16384 -qro -qroconst -qthreaded -O -DB_ENDIAN -DOPENSSL_PIC -D_THREAD_SAFE -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -DSSL_ALLOW_ADH -DAIXSSL_IBM_VERSION=3.0.10.1002
OPENSSLDIR: "/var/ssl"
ENGINESDIR: "/usr/lib/engines-3"
MODULESDIR: "/usr/lib/ossl-modules/32"
Seeding source: os-specific
CPUINFO: N/A
Setting LD_LIBRARY_PATH gives me the correct response:
./openssl version -a
OpenSSL 3.2.1 30 Jan 2024 (Library: OpenSSL 3.2.1 30 Jan 2024)
built on: Fri Feb 16 20:59:37 2024 UTC
platform: aix64-gcc
options: bn(64,64)
compiler: gcc -maix64 -pthread -O -DB_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
OPENSSLDIR: "/custom/opt/apache/openssl"
ENGINESDIR: "/custom /opt/apache/openssl/lib/engines-3"
MODULESDIR: "/custom /opt/apache/openssl/lib/ossl-modules"
Seeding source: os-specific
CPUINFO: N/A
I guess I should add the --prefix and --openssldir flags are set to /custom/opt/apache/openssl
If LD_LIBRARY_PATH or equivalent with a config file is not an option, you'll have to use an rpath for all the applications that you want to make use of the libraries from that path.
You can set LD_LIBRARY_PATH permanently for a user in your shells startup script (.bashrc or .bash_profile) or globally for all users of a shell in the corresponding config located in /etc (names may vary depending on your distribution). However, thats not recommended if you have other application that rely on libraries being in different locations. As @kroeckx notes building your application with -Wl,-rpath=/path/to/openssl would be preferred as that would be application specific.