Linux ldconfig command with examples

The Linux ldconfig command creates, updates, and removes available symbolic links for currently shared libraries. The symbolic links are based on lib directories in /etc/ Linux commands are based on shared libraries. Multiple commands and executables often share libraries, meaning each can use the library without affecting the other.

These shared libraries require some means of managing them. It is ldconfig’s job to create the needed links and caches, useful for managing shared libraries. Let’s see how to use the ldconfig command.

How to use the ldconfig command

The ldconfig checks the filenames and header for various libraries to determine which one has the most up-to-date links when link files are updated.

Also, it creates the /etc/ file, which is useful to speed up library linking by the runtime linker.

The configuration file containing shared libraries used by ldconfig is located at /etc/ The configuration file tells ldconfig to use all configuration files in the specified directory. When you open the file, it contains one line.

1. Using ldconfig to view cached libraries

The ldconfig can show all files currently in the cache. It shows the entire library and lists its location on the command line.

The command to use is:

$ ldconfig – p | head -5

We add “head” to reduce the libraries output by printing the first five lines.

2. Show all libraries

You can use the “-v” option to display any library in any directory. The command iterates through each directory on the system and prints out the name of the directory and the appropriate links created under it.

However, some directories listed under /etc/ do not exist. You might notice some error messages in the output.

$ ldconfig -v

3. Adding new libraries

When a new program is installed by compiling from source, you must inform the system about this new library. There are two ways to do this.

The first is to use the ldconfig command with the “-n” option and update the links directly with only the new library. However, this method does not create a cache. It only updates the link to the new library. For example, if you installed a program like veil in the /opt directory, the following command updates the library link directly:

$ ldconfig -n /opt/dummy/lib

Alternatively, you can use an editor like vi and add /veil/lib to /etc/ to run ldconfig to update all links.

The following command opens the configuration file in which you can add the /opt/veil/lib. Note that veil is our example program. Replace it with the one you need to add in your case.

$ vi /Etc/

To update the cache, run the following command as root:

$ ldconfig

You can verify that the library was added by running the -v option and getting the library name. For example, we can check if the libFLAC library is available with the following command:

$ ldconfig -v grep -I libFLAC

If it is present, it should return an output similar to the following:

ldconfig has additional commands that you can access from the man page. However, the ones we listed using the previous examples are what you need to know when working with libraries and programs.

ldconfig helps to deal with shared libraries. In addition, it is also possible to view the shared libraries used by a specific command. You can use the “ldd” command followed by the program – for example a program like echo.

$ ldd /container/echo


The ldconfig uses the contents of the /etc/ file to create symbolic links and a cache, /etc/ This is read by programs, especially executable and shared programs. This guide covers the various files that ldconfig worked with and shows examples of using the Linux ldconfig command to view and add libraries.

Related Posts