How to Check Package Dependencies in Linux? [3 Easy Ways]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

You may need to install software in your Linux system to perform your daily tasks. For example, a VLC player to run media files like music, and video, and a text editor to prepare documents. In Linux, the software is installed in the form of a package. Sometimes installing a package successfully may depend on some other packages called dependencies. In this case, you have to install dependencies before installing the software. So, I’ll show you how to check package dependencies most easily in this tutorial.

Process flow chart to check package dependencies in Linux:

Flow chart of 3 methods describing how to check dependencies in linux

[Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS]

Checking Dependencies in Various Distributions in Linux

There are many distributions available in Linux. Each distribution has different commands for checking the dependencies of a package. Here is a list of those commands to check dependencies for different distributions:

Distribution Command
RHEL yum deplist <package-name>
Fedora sudo dnf info <package-name>
ArchLinux pactree -r <package-name>
OpenSUSE sudo zypper info <package-name>

Note: Replace <package-name> with the actual package name.

If you are using ArchLinux and pactree is not installed in your system, run the following command to install it first:

sudo pacman -S pacman-contrib

Now, I’ll show you some methods to check dependencies in the Ubuntu distribution.

3 Methods to Check Package Dependencies in Ubuntu

Sometimes checking the dependencies of a software package becomes the first step of installing the software. You can use 3 different methods to check dependencies in Ubuntu. These are:

1) apt package manager

  • apt show command
  • apt-cache command

2) dpkg command

3) Third-party tool called rDpenends

You can read our Comparative Analysis of Methods to distinguish between these three methods and best pick one for your need.

Method 01: Use APT to Check Package Dependencies in Linux

The apt package manager provides two straightforward ways to check any software dependency. These are 1) apt show command and 2) apt-cache command. You just have to use the sudo command to use the “apt show” method.

Suppose, you want to install VLC player. Before installing, you want to check the dependency packages of VLC.

A. Using apt show Command to Check Package Dependencies

This command provides information about the package such as version, type of the package, total download size, etc. Also, the output has a special section – “Depends” that lists all the dependency packages with their required version.

Steps to Follow >

➊ At first, open your Ubuntu terminal. You can press CTRL+ALT+T.

➋ Then, run the following command in the command line:

sudo apt show vlc

EXPLANATION

  • sudo: Grants administrative privileges.
  • apt: It is the package management tool for Ubuntu. It is used to manage software packages including installation, removal, and updates.
  • show: The show subcommand is used with apt to display information about a specific package.
  • vlc: Package name.

➌ Now, give the password of the currently logged-in user and hit ENTER.apt show command showing dependency of vlc The highlighted box shows the dependency package list with the version number inside the “Depends” section.

B. Using apt-cache Command to Check Package Dependencies

This command lists out only the dependency package name. It doesn’t show the version, type of package, publisher information, etc. The output only focuses on the dependency package name to enhance readability for you.

Steps to Follow >

➊ At first, open your Ubuntu terminal. You can press CTRL+ALT+T.

➋ Then, run the following command in the command line:

apt-cache depends vlc

EXPLANATION

  • apt-cache: This command interacts with the APT (Advanced Package Tool) cache, which stores information about available packages and their dependencies.
  • depends: This option displays the dependencies of a specified package.
  • vlc: Package name.

➌ Now, enter the password of the currently logged-in user and hit ENTER.apt-cache depends command showing the dependencies of vlc in the terminal.The highlighted “Depends” section lists mandatory packages for VLC. Also, the output shows some recommendations and suggestion packages for a better user experience.

Method 02: Use DPKG to Check Package Dependencies of an Existing Package in Linux

dpkg is a package manager for Debian distribution. It can also be used to install, uninstall and update packages. You can use dpkg to check dependency if a package is already installed in your system. I will show you dpkg dependency checking for VLC. At first, I will install VLC.

Step 01: Install the Package on Ubuntu

If you want to use dpkg to know what are the dependency files of a package, first you have to install the package. You can skip this step if you have the package already installed in your system. If you don’t, follow the steps to install the package:

Steps to Follow >

➊ Open your Ubuntu terminal. Press CTRL+ALT+T.

➋ Type the following command:

sudo apt install vlc
EXPLANATION
  • install: It is used to install new packages on the system.
  • vlc: Package name.

➌ Now, give the password of the current user and press ENTER.terminal output of installing vlc.This command installs the VLC player on your system. If you have already installed VLC in your system then the output will look like this:terminal output shows vlc is already installed.So, you have VLC downloaded and installed in your system.

Step 02: Check Dependencies Using DPKG

Once you have installed the package, anytime you can check the dependencies of the package using dpkg. To check dependencies using DPLG follow the steps:

Steps to Follow >

➊ Open your Ubuntu terminal by pressing CTRL+ALT+T.

➋ Type the following command:

dpkg -s vlc

EXPLANATION

  • dpkg: It is a package management tool in Ubuntu and other Debian-based Linux distributions. It is used to manage individual software packages in the system.
  • -s: This is used with dpkg to query the status of a specific package.
  • vlc: Package name.

➌ Tap ENTER key.dpkg command showing dependencies of vlc the terminal.The output lists dependencies after version, publisher, size, and some other information. It also shows the required version of dependency packages in braces.

Method 03: Use APT-rDepends Tool to Check Package Dependencies in Linux

APT-rDepends is a popular and user-friendly third-party tool for checking package dependencies. This tool performs a recursive listing of package dependencies like apt-cache but it also shows the required version of those dependencies.

Step 01: Install APT-rDepends on Ubuntu

Installing rDepends is a one-time process. Generally, this tool is not installed in your system by default. So, you have to install it before using. Follow this steps to install rDepends:

Steps to Follow >

➊ At first, open your Ubuntu terminal. You can press CTRL+ALT+T.

➋ Type the following command in the command line to install rDepends on your system:

sudo apt-get install -y apt-rdpends

EXPLANATION

  • apt-get: This is one of the package management tools in Ubuntu. It is used to interact with the apt manager to manage software package installation.
  • -y: The -y option stands for “yes” and is used to automatically answer “yes” to any prompts during the installation process.
  • apt-rdepends: This is the name of the package you are now installing.

➌ Press ENTER.

➍ Now, give the password of the currently logged-in user and hit ENTER.installing third-party tool called rDepends by apt.The above command installs apt-rdepends package to help you check other package dependencies. If this installation command doesn’t work for you, see our Common Challenge section to overcome this.

Step 02: Check Dependencies Using rDepends

Once you install rDepends on your system you can use it to check dependency for any packages. The “apt-rdepends” has the following syntax:

sudo apt-rdepends <PackageName>

Let’s use it for checking the dependencies of VLC. To do so, type the following command in the command line:

sudo apt-rdepends vlc

checking dependency of vlc by rdepends command.This command will show all the dependencies in a recursive manner. For example: VLC depends on vlc-bin, vlc-bin depends on libc6, libc6 depends on libcrypt1 and so on. So, this command will help you to see all the nested dependencies required for installing the VLC player.

Comparative Analysis of Methods to Check Package Dependencies in Linux

I’ve discussed three methods for checking the dependencies of a package in Linux, which can lead you to confusion when selecting the most suitable option. Hence, to simplify your decision-making process, this section provides a comparative analysis of the three distinct approaches. By exploring the pros and cons of each scenario, you can make an informed choice that aligns with your needs and preferences.

Methods Pros Cons
Method 01
  • Single line command.
  • Has options to view the dependency list with or without version information.
  • Works both for installed and not installed software packages.
  • Compressed view with required version information.
  • Nice list view but without the required version information not shown.

 

Method 02
  • Shows a dependency list with version information.
  • Shows dependency information only for already installed packages.
Method 03
  • List out all dependencies in a recursive manner that helps to visualize all interdependencies for a software package.
  • Needs to install a third-party package that may arise a problem for beginners.

When you are deciding to install a software and want to see the direct dependencies you should go with method 1. In the case you also want to figure out all the interdependencies among dependency packages you should go with method 3. Generally, developers use method 3 to list out all recursive dependencies. Moreover, if you want to see dependencies of a software that is already installed in your system you can use method 2, but you can use method 1 also in this case.

Common Challenge: rDepends Installation by “apt-get” May Not Work at First

The apt-rdepends installation shown in method 3  may fail the first time when you run sudo apt-get install -y apt-rdepends command. Updation of apt-get resolves the problem most of the time.

Type the following command on your Ubuntu terminal if apt-rdepends installation fails:

sudo apt-get update

EXPLANATION

  • apt-get: This is one of the package management tools in Ubuntu. It is used to interact with the apt manager to manage software package installation.
  • update: It is used to update any packages on the system.

running apt-get updateAfter this updation, you can proceed again in installing apt-rdepends..

Conclusion

In this tutorial, I have illustrated the 3 easiest ways to check the dependencies of a package in a Linux system. This article will introduce you to the basic command structure provided by Linux package managers to check package dependencies.  Here, I have shown the dependencies of VLC player throughout the tutorial to better demonstrate the difference among the output of each method. You can use it for other software packages by just replacing the package name. Moreover, these three methods include dependency checking that is suitable for beginners to advanced users.

People Also Ask

How to find package dependency in Linux?

Run the following command to find the dependencies of a package: sudo apt show <package-name>. Replace <package-name> with the actual package name.

How do I find all dependencies of a package?

To see all the dependencies of a package, you need another third-party package to figure out recursive dependencies. If you have apt-rdepends installed in your system then use the following syntax: sudo apt-rdepends <package name>. Replace <package-name> with the actual name of the package.

How do I list all npm dependencies?

Use the npm list to show the installed packages in the current project as a dependency tree. Run npm list –depth=n to show the dependency tree with a specified depth. Moreover, use npm list –prod to show packages in the dependencies. Use npm list –dev to show packages in the devDependencies.

How to check npm package dependencies?
Run  npm ls <package name> and it’ll show you a set of files that are dependent on the package. You can also use npm explain <package name> to understand why a specific package is needed and if it depends on any other package in your project.


Related Articles


<< Go Back to Dependencies in Linux | Package Management in Linux | Learn Linux Basics

5/5 - (3 votes)
Ashikur Rahman

Hello, I’m Ashikur Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation in Computer Science and Engineering from Khulna University of Engineering & Technology (KUET). Also, I’m pursuing my master’s in the same department at Bangladesh University of Engineering & Technology (BUET). I like to learn new technologies, contribute, and share those with others. Here my goal is to provide beneficial and user-friendly articles on Linux distribution for everyone. Read Full Bio

2 thoughts on “How to Check Package Dependencies in Linux? [3 Easy Ways]”

  1. I am 49 years old and I work in IT since ages but I have never seen such a great, detailed but explicited way to onboard with packaging. Congratulations Ashi!

    Reply
    • Hello DESMAREST,
      Thank you so much for your incredibly kind words! It’s heartening to know that my explanation resonated with someone as experienced as yourself. If you have any questions or if there’s anything specific you’d like to explore further, feel free to reach out.

      Reply

Leave a Comment