Linux

How to Use ldd to Analyze Library Dependencies in Linux

This guide explains how to use the ldd utility to display dynamic library dependencies in Linux. You'll learn to analyze executable files and find missing libraries.

Updated at February 17, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Linux (Ubuntu 22.04+, CentOS 7+, Debian 11+)Any distribution with the ldd utility installed

Introduction / Why This Is Needed

The ldd (List Dynamic Dependencies) utility is a standard Linux tool for viewing the dynamic dependencies of an executable file. It shows which shared libraries (.so files) need to be loaded when the program starts. This is essential for:

  • Diagnosing errors like error while loading shared libraries: libXYZ.so: cannot open shared object file.
  • Understanding which packages need to be installed on a clean system.
  • Verifying binary integrity and detecting potential issues with RPATH/RUNPATH.

After completing this guide, you will be able to quickly locate and resolve missing library issues.

Requirements / Preparation

Before you begin, ensure that:

  1. You have access to a Linux terminal (Ubuntu, CentOS, Fedora, Debian, etc.).
  2. The ldd utility is installed. It is typically included in the libc6 (Debian/Ubuntu) or glibc (RHEL/CentOS) packages. You can verify with:
    ldd --version
    
  3. You have an executable file (in ELF format) to analyze. This can be any binary on your system, such as /usr/bin/ls or your own compiled file.
  4. You have read permissions for the file. If the file belongs to another user, use sudo or copy it to your directory.

Step-by-Step Instructions

Step 1: Basic ldd Execution

Simply specify the path to the executable:

ldd /bin/ls

Example output:

linux-vdso.so.1 (0x00007ffd6d7f9000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f8c1a400000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8c19e00000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f8c19a00000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8c1a800000)

Each line contains:

  • The library name (e.g., libc.so.6).
  • The => arrow and the full path where the library will be loaded.
  • The memory address (in parentheses), if the library is already loaded in the current process (may vary per run).

Step 2: Interpreting Key Elements

  • linux-vdso.so.1 — a virtual dynamic library provided by the kernel (not a real file on disk).
  • /lib64/ld-linux-x86-64.so.2 — the dynamic loader (interpreter); the program will not run without it.
  • If not found appears instead of a path, the library is missing from standard search paths (/lib, /usr/lib, LD_LIBRARY_PATH).

Step 3: Handling Missing Libraries

If your output contains lines like libsomething.so => not found, do the following:

  1. Find the package containing the library. For Debian/Ubuntu:
    apt-file search libsomething.so
    

    If apt-file is not installed, first install it: sudo apt update && sudo apt install apt-file && sudo apt-file update.
    For RHEL/CentOS/Fedora:
    yum provides */libsomething.so
    

    or
    dnf provides */libsomething.so
    
  2. Install the found package:
    sudo apt install package_name   # Debian/Ubuntu
    sudo yum install package_name   # RHEL/CentOS
    
  3. Update the library cache:
    sudo ldconfig
    
  4. Re-check the file with ldd.

Step 4: Using Options for Advanced Analysis

  • -v (verbose) — shows all library matches, including duplicates and versions.
    ldd -v /usr/bin/ssh
    
  • -u — lists unused direct dependencies (useful for cleaning up DT_NEEDED in the ELF header).
    ldd -u /usr/bin/ssh
    
  • --version — displays the ldd utility version.

Step 5: Security and Alternatives

⚠️ Important: Running ldd on untrusted executables can be dangerous! Some binaries may execute code via DT_RPATH/DT_RUNPATH. For security, use instead:

objdump -p /path/to/file | grep NEEDED

or

readelf -d /path/to/file | grep NEEDED

These commands only read the ELF header and do not execute any code.

Verifying the Result

A successful outcome:

  • The ldd output contains no not found lines.
  • All libraries have full paths.
  • The dynamic loader (ld-linux.so) is correctly listed.

If you installed missing libraries, restart the program to confirm it runs without errors.

Potential Issues

ProblemSymptomsSolution
Library not foundlibXYZ.so => not foundInstall the package containing the library and run sudo ldconfig.
Wrong architectureldd: /path/file: failed to load module: invalid ELF headerThe file is compiled for a different architecture (e.g., 32-bit on a 64-bit system). Install compatible libraries (e.g., libc6-i386).
Static binarystatically linked in outputLibraries are embedded in the file. No dependencies exist; ldd is not applicable.
No read permissionsldd: /path/file: Permission deniedAdd permissions: chmod +r /path/file or use sudo ldd /path/file (with caution!).
Outdated ldd versionUnexpected output format or errorsUpdate the libc6/glibc package: sudo apt upgrade libc6 or sudo yum update glibc.

If the issue persists, check the LD_LIBRARY_PATH and LD_DEBUG environment variables for detailed library loading diagnostics.

F.A.Q.

Why is the ldd command needed?
Can ldd be used for static binaries?
Is it safe to run ldd on unknown files?
What should I do if ldd shows 'not found' for a library?

Hints

Check if ldd utility is installed
Run ldd on the target executable file
Analyze the output
Install missing libraries
Use additional options for detailed analysis

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community