Linux Commands To Manage Shared Libraries

The commands ldd and ldconfig are the Linux tools for managing shared libraries. You might have noticed many files starting with lib* in /lib and /usr/lib directories of your Linux machine. These files are called libraries. A library is a collection of objects, functions etc. A library makes it possible for a program to use common routines without the administrative overhead of maintaining their source code, or the processing overhead of compiling them each time the program is compiled.

There are mainly two types of libraries in Linux. They are:

1. Static library.

These are the libraries with “.a” extension. These libraries are included (a separate copy) into the programs that require its functions.

2. Dynamic library.

These are the libraries with “.so” extension. These libraries will be linked to the program while executing the program that requires it. That is, there will not be separate copies of libraries for the programs using it, rather than it dynamically links to it. In this article, we will go through the commands “ldd” and “ldconfig” which are used to manage the shared libraries.

Please note down the following points before going through the command:

- The file, is the dynamic linker or loader which checks for the desired link or library cache for the requested program and loads it.

- The cache file, /etc/ contains a list of libraries found in the directories specified in /etc/ This helps to provide faster dynamic linking.

- The file /etc/ specifies the directories where to search for libraries


ldconfig creates the necessary links and cache (for use by the run-time linker, to the most recent shared libraries found in the directories specified on the command line, in the file/etc/, and in the trusted directories (/usr/lib and /lib).


Execute the following command to set up the correct links for the shared binaries and rebuild the cache.

# ldconfig –v

Execute the following command after the installation of a new shared library will properly update the shared library symbolic links in /lib.

# ldconfig -n /lib

Following command will print the current cache.

#ldconfig -p

Common shared library related errors.

1. Missing library error.

You may encounter missing library error even though the mentioned libraries are available in the new installation path “/opt/newinstall/lib”. This is because the system is not aware of this directory to check for libraries. This can be fixed in any of the two ways.

a. Execute the following command,

# ldconfig -n /opt/newinstall/lib

b. You can see the following include line in /etc/ file:


So, create a file in /etc/ folder, say newinstall.conf with the following content.


Then, execute:

# ldconfig

2. Dynamic linker error, can’t map cache files.

This may be due to corrupted cache file. This can be resolved by rebuilding the cache file using ldconfig.


ldd command.

ldd prints the shared libraries required by each program or shared library specified on the command line.

[[email protected] root]# ldd /bin/mv => /lib/ (0×40016000) => /lib/ (0x4001c000) => /lib/ (0×40141000)
/lib/ => /lib/ (0×40000000)
[[email protected] root]#

# ldd -d execute_file

Perform relocations and report any missing objects (ELF only).

# ldd -r execute file

Perform relocations for both data objects and functions, and report any missing objects or functions (ELF only).

Bobbin Zachariah 9:26 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.