How to Add or Remove Library Path in RHEL

In Red Hat Enterprise Linux systems, you can modify the list of library paths that is not loaded by default.

What are Linux libraries?

If you have libraries outside the common and trusted library directories such as /usr/lib, /usr/lib64, /lib, or /lib64, you can add the directory by using the ldconfig command.

If you have compiled a new set of libraries, it is placed in the /usr/local/lib directory, in most cases. We are going to use the /usr/local/lib library path, the location of our newly compiled unixODBC 2.3 libraries, that we need to check, add, or remove in our examples.

Checking if the Library Path is Loaded

To check if the directory containing your libraries are already loaded, run the following command to verify:

ldconfig -v

The command `ldconfig -v` will list all the current library paths loaded by ldconfig.

Adding a Library Path

Use the following steps to add library paths:

1. Create the file unixODBC-2.3.conf and place the directory in this file. This will serve as a container for the library path.

echo "/usr/local/lib" > /etc/ld.so.conf.d/unixODBC-2.3.conf

2. Reload the ldconfig command to update the dynamic linker.

ldconfig

3. Check if the path is now in the list of links.

ldconfig -v

You should see something like this:

     /usr/local/lib:
            libodbc.so.1 -> libodbc.so.1.0.0
            libodbcinst.so.1 -> libodbcinst.so.1.0.0
            libodbccr.so.1 -> libodbccr.so.1.0.0

Removing a Library Path

1. Remove the file unixODBC-2.3.conf.

rm -f /etc/ld.so.conf.d/unixODBC-2.3.conf

2. Reload the ldconfig command to update the dynamic linker.

ldconfig

3. Check if the path has been removed from the list of links.

ldconfig -v