ldconfig on Linux: Update Shared Library Cache
The ldconfig command in Linux creates the links and rebuilds the index of the dynamic libraries in the /etc/ld.so.cache file. It looks for libraries in the directories /usr/lib and /lib, as well as in the directories listed in /etc/ld.so.conf, as well as the directory informed on the command line.
The most common options are:
- -p: Lists the contents of the /etc/ld.so.cache cache.
- -v: Shows the progress of the cache update.
- -f: file informs a different configuration file from the standard /etc/ld.so.conf.
Examples:
# ldconfig –p
229 libs found in cache ‘/etc/ld.so.cache’
src_vipa.so (ELF) => /usr/lib/src_vipa.so
libz.so.1 (libc6) => /lib/libz.so.1
libz.so.1 (libc6) => /usr/lib/libz.so.1
liby2util.so.3 (libc6) => /usr/lib/liby2util.so.3
liby2pm.so.2 (libc6) => /usr/lib/liby2pm.so.2
liby2.so.2 (libc6) => /usr/lib/liby2.so.2
libyui.so.2 (libc6) => /usr/lib/libyui.so.2
libycp.so.2 (libc6) => /usr/lib/libycp.so.2
# ldconfig –v
/usr/X11R6/lib:
libSM.so.6 -> libSM.so.6.0
libdps.so.1 -> libdps.so.1.0
libXrender.so.1 -> libXrender.so.1.2
(…)
LD_LIBRARY_PATH
It is also possible to provide the runtime linker ld.so with a list of extra directories that may contain shared libraries through the LD_LIBRARY_PATH environment variable.
A list of directories can be configured, separating them by two colons ":". This list precedes the list in the ls.so.conf file.
# set | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=/usr/lib
For security reasons, the LD_LIBRARY_PATH variable is ignored by ld.so when it makes links of programs that have the SUID or SGID bit enabled.
Its use is common to test new routines in libraries under development instead of running the routines already installed.
Every time a new library is installed, or library version, it is necessary to update the ld.so linker cache with the ldconfig command.
Rarely you will need to use the ldd and ldconfig commands if you install software on Linux using a package manager, because the managers also install the dependencies of a software, so that the libraries that the software needs are also installed and the ld.so.cache file is rebuilt at the time of package installation.
But if you download a software in source code, and are going to compile this software, you can be sure that you will possibly run into an error of missing libraries or incorrect version.
The list of libraries used by a program can be obtained with the ldd command.
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.