- How to Check Dependencies of a Package in Ubuntu/Debian-based Linux Distributions
- What is package dependency in Ubuntu?
- Check dependencies of a package in Ubuntu and Debian based distributions
- Checking dependencies with apt show
- Use apt-cache for getting just the dependencies information
- Check the dependencies of a DEB file using dpkg
- Checking dependencies and reverse dependencies with apt-rdepends
- Determine direct shared object dependencies of a Linux binary?
- 4 Answers 4
- How to find out the dynamic libraries executables loads when run?
- 8 Answers 8
- How to check what libraries are used by a program or process on Linux
- Check Shared Library Dependencies of a Program Executable
- Check Shared Library Dependencies of a Running Process
- Support Xmodulo
- How to show all shared libraries used by executables in Linux?
- 13 Answers 13
How to Check Dependencies of a Package in Ubuntu/Debian-based Linux Distributions
Last updated October 29, 2020 By Abhishek Prakash 8 Comments
Installing applications via command line is quite easy in Ubuntu/Debian. All you need to do is to use apt install package_name.
But what if you want to know the dependencies of a package before or after installing it?
In this tutorial, I’ll show you various ways to see the dependencies of a package in Ubuntu and other Debian-based Linux distributions that use APT package management system.
What is package dependency in Ubuntu?
If you didn’t know already, when you install a software package in Linux, sometimes, it needs other packages to function properly. These additional packages are called dependencies. If these dependency packages are not installed on the system, it is usually installed automatically with the package.
For example, the GUI tool HandBrake for converting video formats needs FFmpeg, GStreamer. So for HandBrake, FFmpeg and GStreamer are the dependencies.
If you don’t have these packages installed on your system, they will be automatically installed when you install HandBrake on Ubuntu.
Check dependencies of a package in Ubuntu and Debian based distributions
As it often happens in Linux, there are more than one way to achieve the same result. Let’s see various ways to see the dependencies of a package.
Checking dependencies with apt show
You can use the apt show command to display details of a package. Part of this information is dependencies and you can see it in the line starting with Depends.
For example, here’s what it shows for ubuntu-restricted-extras package.
As you can see, ubuntu-restricted-extras package depends on ubuntu-restricted-addons package.
Here’s a catch! The dependency package may also depend on some other package and the chain could go on. Thankfully, the APT package manager handles this for you by automatically installing all the dependencies (most of the time).
What is recommended package?
Did you notice the line starting with Recommends in the above output?
Recommended packages are not direct dependencies for the package but they enable additional features.
As you can see, ubuntu-restricted-extras has ttf-mscorefonts-installer as recommended package for installing Microsoft Fonts on Ubuntu.
The recommended packages are also installed by default and if you explicitly want to forbid the installation of recommended package, use the –no-install-recommends flag like this:
sudo apt install –no-install-recommends package_name
Use apt-cache for getting just the dependencies information
The apt show has way too many information. If you want to get the dependencies in a script, the apt-cache command gives you a better and clean output.
The output looks much clean, does it not?
Check the dependencies of a DEB file using dpkg
Both apt and apt-cache command work on the packages that are available from the repositories. But if you download a DEB file, these command won’t work.
In this case, you can use the dpkg command with -I or –info option.
The dependencies can be seen in the line starting with Depends.
Checking dependencies and reverse dependencies with apt-rdepends
If you want more details on the dependencies, you can use the apt-rdepends tool. This tool creates the complete dependency tree. So, you get the dependency of a package and the dependencies of the dependencies as well.
It is not a regular apt command and you’ll have to install it from the universe repository:
The output is usually quite large depending on the dependency tree.
The apt-rdepends tool is quite versatile. It can also calculate the reverse dependencies. Which means, you can see what other packages depend on a certain package.
The output could be pretty big because it will print the reverse dependency tree.
I hope this quick tutorial was helpful in improving your command line knowledge a bit. Stay tuned for more such tips.
Like what you read? Please share it with others.
Источник
Determine direct shared object dependencies of a Linux binary?
How can I easily find out the direct shared object dependencies of a Linux binary in ELF format?
I’m aware of the ldd tool, but that appears to output all dependencies of a binary, including the dependencies of any shared objects that binary is dependent on.
4 Answers 4
You can use readelf to explore the ELF headers. readelf -d will list the direct dependencies as NEEDED sections.
If you want to find dependencies recursively (including dependencies of dependencies, dependencies of dependencies of dependencies and so on)…
The objdump tool can tell you this information. If you invoke objdump with the -x option, to get it to output all headers then you’ll find the shared object dependencies right at the start in the «Dynamic Section».
For example running objdump -x /usr/lib/libXpm.so.4 on my system gives the following information in the «Dynamic Section»:
The direct shared object dependencies are listing as ‘NEEDED’ values. So in the example above, libXpm.so.4 on my system just needs libX11.so.6 and libc.so.6 .
It’s important to note that this doesn’t mean that all the symbols needed by the binary being passed to objdump will be present in the libraries, but it does at least show what libraries the loader will try to load when loading the binary.
Источник
How to find out the dynamic libraries executables loads when run?
I want to find out the list of dynamic libraries a binary loads when run (With their full paths). I am using CentOS 6.0. How to do this?
8 Answers 8
You can do this with ldd command:
readelf -d $executable | grep ‘NEEDED’
Can be used if you can’t run the executable, e.g. if it was cross compiled, or if you don’t trust it:
In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1, which causes the linker to display the library dependencies. Be aware, however, that in some circumstances, some versions of ldd may attempt to obtain the dependency information by directly executing the program. Thus, you should never employ ldd on an untrusted executable, since this may result in the execution of arbitrary code.
Note that libraries can depend on other libraries, so now you need to find the dependencies.
A naive approach that often works is:
but the more precise method is to understand the ldd search path / cache. I think ldconfig is the way to go.
Choose one, and repeat:
/maps for running processes
Mentioned by Basile, this is useful to find all the libraries currently being used by running executables. E.g.:
shows all currently loaded dynamic dependencies of init (PID 1 ):
This method also shows libraries opened with dlopen , tested with this minimal setup hacked up with a sleep(1000) on Ubuntu 18.04.
Источник
How to check what libraries are used by a program or process on Linux
Last updated on November 28, 2020 by Dan Nanni
You can use the following methods to identiy which shared librariies a given program executable (e.g., /path/to/program ) or a given running process (e.g., PID 1149 ) depends on.
Check Shared Library Dependencies of a Program Executable
To find out what libraries a particular executable depends on, you can use ldd command. This command invokes dynamic linker to find out library dependencies of an executable.
Note that it is not recommended to run ldd with any untrusted third-party executable because some versions of ldd may directly invoke the executable to identify its library dependencies, which can be security risk.
Instead, a safer way to show library dependencies of an unknown application binary is to use the following command.
Check Shared Library Dependencies of a Running Process
If you want to find out what shared libraries are loaded by a running process, you can use pldd command, which shows all shared objects loaded into a process at run-time.
Note that you need root privilege to run pldd command.
Alternatively, a command line utility called pmap , which reports memory map of a process, can also show shared library dependencies of a running process.
Support Xmodulo
This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin ( 1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g ).
Источник
How to show all shared libraries used by executables in Linux?
I’d like to know which libraries are used by executables on my system. More specifically, I’d like to rank which libraries are used the most, along with the binaries that use them. How can I do this?
13 Answers 13
- Use ldd to list shared libraries for each executable.
- Cleanup the output
- Sort, compute counts, sort by count
To find the answer for all executables in the «/bin» directory:
Change «/bin» above to «/» to search all directories.
Output (for just the /bin directory) will look something like this:
Edit — Removed «grep -P»
I didn’t have ldd on my ARM toolchain so I used objdump:
This works better than ldd when the executable uses a non default loader
to learn what libraries a binary uses, use ldd
You’d have to write a little shell script to get to your system-wide breakdown.
Check shared library dependencies of a program executable
To find out what libraries a particular executable depends on, you can use ldd command. This command invokes dynamic linker to find out library dependencies of an executable.
> $ ldd /path/to/program
Note that it is NOT recommended to run ldd with any untrusted third-party executable because some versions of ldd may directly invoke the executable to identify its library dependencies, which can be security risk.
Instead, a safer way to show library dependencies of an unknown application binary is to use the following command.
$ objdump -p /path/to/program | grep NEEDED
readelf -d recursion
redelf -d produces similar output to objdump -p which was mentioned at: https://stackoverflow.com/a/15520982/895245
But beware that dynamic libraries can depend on other dynamic libraries, to you have to recurse.
Choose one, and repeat:
/maps for running processes
This is useful to find all the libraries currently being used by running executables. E.g.:
shows all currently loaded dynamic dependencies of init (PID 1 ):
This method also shows libraries opened with dlopen , tested with this minimal setup hacked up with a sleep(1000) on Ubuntu 18.04.
On OS X by default there is no ldd , objdump or lsof . As an alternative, try otool -L :
In this example, using which openssl fills in the fully qualified path for the given executable and current user environment.
On UNIX system, suppose binary (executable) name is test. Then we use the following command to list the libraries used in the test is
With ldd you can get the libraries that tools use. To rank the usage of libraries for a set of tool you can use something like the following command.
(Here sed strips all lines that do not start with a tab and the filters out only the actual libraries. With sort | uniq -c you get each library with a count indicating the number of times it occurred.)
You might want to add sort -g at the end to get the libraries in order of usage.
Источник