Managing dependencies is an integral part of maintaining your Linux system. Software is complex and relies on a multitude of shared libraries and files. Sometimes, it becomes hard to keep track of the files required by an application.
This is where the ldd command on Linux comes into play. ldd is a resourceful command-line tool to keep track of the shared object dependencies required by an application.
Let’s learn how you can use the ldd command to your advantage and become a pro at managing dependencies on Linux!
What Are Package Dependencies?
Software is not just standalone source code but rather an amalgamation of native source code and borrowed code from external libraries. When these libraries and other shared objects are missing from your system, an application depending on them may malfunction or straight up refuse to even launch.
All these shared files, packages, libraries, etc., are cumulatively called dependencies on Linux. Although this short definition gives you a rough idea about dependencies, the real picture is a bit more complex than that, and that’s why it’s important to learn what package dependencies are in depth.
What Is the ldd Command and How Does It Work?
ldd is an abbreviation for List Dynamic Dependencies. As the name suggests, ldd lists all the shared objects required by an application.
It works by invoking the dynamic linker with specially set environment variables. When you run ldd with the location of a binary, it returns an output containing the list of dependencies, their location, and a hexadecimal value representing where in memory they are loaded.
Finding Shared Object Dependencies With ldd Command
Now that you have a clear idea of what ldd is all about, let’s get hands-on and learn how you can find software dependencies with it.
Before you learn how to use ldd, first, confirm if you have it installed on your system by printing out the installed version of ldd:
If it returns a “command not found” error, you need to first install ldd.
On Ubuntu- and Debian-based systems, run:
sudo apt install libc-bin
For Arch-based distributions:
sudo pacman -S glibc
On RHEL and Fedora:
sudo dnf install glibc-common
With ldd installed, you can now focus on learning how to use it. Here’s the basic syntax for the ldd command:
In case you don’t know the location of the binary, you can make use of one of the many Linux command-line operators and combine the output of the which command with ldd to find the dependencies for the package:
ldd -flag $(which binary_name)
ldd command offers four different options to modify the output. They are:
- -v: Prints verbose output including additional information such as version information for each dependency
- -u: Prints all unused dependencies, meaning dependencies that are loaded but not implemented
- -d: Prints missing objects and performs relocations
- -r: Prints missing objects and functions and performs relocations
Managing Package Dependencies on Linux
With ldd in your software arsenal, you’ll be able to troubleshoot shared object dependency-related problems with your application.
Moreover, as ldd also outputs the location where a library is loaded, you’ll be able to debug an application and better understand how a particular library is implemented. ldd also prints out the versions of shared libraries used in an application.
Using this feature, you can audit your applications for any potential vulnerabilities associated with an outdated version of a shared library.
Dependency management is a core skill that’s crucial to keeping your Linux system healthy. However, sometimes, a package may break despite all its dependencies being healthy. It’s important you know how to find and fix broken packages.