How to Check APT Dependency Tree in Linux? [4 Methods]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The dependency tree refers to the hierarchical structure of dependencies that exist between software packages on a Linux distribution. In a dependency tree, packages are organized in a way that shows which packages depend on others to function properly. Here, dependencies can be either runtime dependencies, which are required for the software to run, or build dependencies, which are required to compile or build the software.

Key Takeaways

  • Getting a comprehensive idea about the dependency tree.
  • Learning the ways to check apt dependency tree using various techniques.

Requirements

Process Flow Chart

[Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS]4 methods to check apt dependency tree

What is Dependency in Linux?

Dependencies in Linux refer to some software packages that are prerequisites to another package. Those packages are required for the successful and complete installation of an intended package. To ensure reusability, Linux treats a software package as a collection of modules that can be used by different packages. So, checking the dependencies sometimes becomes crucial in order to understand the interdependency of modules in a package.

What is APT Dependency Tree?

APT (Advanced Package Tool) is a package management tool used in Debian-based Linux distributions. APT dependency tree is the hierarchical structure of dependencies that is previewed by APT. Actually, it refers to the recursive form of dependencies. If you are using Ubuntu or any other Debian-based Linux distribution, you can use the apt package manager tool to list the hierarchical dependency structure of a package. For example, a part of the dependency tree of VLC player looks like this:partial view of apt tree of VLC player

4 Methods to Check APT Dependency Tree in Linux

Checking the dependency tree is a critical and fundamental step in various areas of system administration, particularly in software development and package management. In this tutorial, I’ll show you 4 different methods to check apt dependency tree in different visualization formats.

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

Method 01: Using “apt-rdepends” to Check Dependency Tree

apt-rdepends is a command-line tool in Debian-based Linux distributions like Ubuntu. It recursively displays the dependencies of a specified package. This means, it not only shows the direct dependencies but also forms a dependency tree to show the dependencies of those dependencies. “apt-rdepends” has the following syntax:

sudo apt-rdepends <package name>

Let’s use this tool for checking the dependencies of VLC. To do so, follow the steps below:

Steps to Follow >

➊ Open the Ubuntu terminal. You can press CTRL+ALT+T.

➋ Type the command:

sudo apt-rdepends vlc
EXPLANATION
  • sudo: Grants administrative previleges.
  • apt-rdepends: Calls apt-rdepends to list dependencies.
  • vlc: Package name.

➌ Press ENTER.apt-rdepends prints VLC player's dependencyThis 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.

Note: If you want to see the reverse dependency tree, that indicates which packages require the mentioned package, you can use the following syntax:

sudo apt-rdepends -r <package name>

Replace <package name> with the actual name of the package you want to investigate.

Method 02: Using Debtree to Check Dependency Tree in Ubuntu

Debtree is a command-line tool in Debian-based Linux distributions like Ubuntu. Generally, it is used to generate a visual representation of the dependency tree for a specified Debian package. For this reason, this tool can be particularly useful for understanding the recursive dependencies of a package and how they are interconnected. However, debtree has the below syntax to print a digraph of a package’s dependency tree:

debtree <package name>

This command will show you a hierarchical tree-like structure that displays the dependencies of the specified package and how they are interconnected. Now, follow the steps to view the dependency tree of VLC using debtree.

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Type the command:

debtree vlc
EXPLANATION
  • debtree: Calls the debtree utility.
  • vlc: Package name.

➌ Press ENTER.debtree shows digraph description of VLC

OUTPUT ANALYSIS

The type of dependency between packages is indicated by line type and the color of the arrow indicating the dependency:

Represents Denoting Style
Build-Depends Dark gold, bold
Build-Depends-Indep Light gold
Pre-Depends Purple, bold
Depends Blue
Recommends Black
Suggests Red
Conflicts Black, dotted
Provides Green, inverted arrow

Method 03: Using APT-Cache to Check Dependency Tree in Ubuntu

APT-Cache is also a command-line tool in Debian-based Linux distributions like Ubuntu. Actually, it is a part of the Advanced Package Tool (APT) package management system and is used for querying and displaying dependency information related to software packages that are available in the system’s package cache. To preview dependency of VLC using this tool, you have to follow these steps:

➊ Open the Ubuntu terminal. You can press CTRL+ALT+T.

➋ Type the command:

apt-cache showpkg vlc | less
EXPLANATION
  • apt-cache: Calls the apt-cache package management tool.
  • showpkg: Command to show forward and reverse dependencies.
  • vlc: Package name.
  • | (Piping Symbol): Transfers the output of a command as the input of the next command.
  • less: Shows the output one screen at a time thus improving readability.

➌ Press ENTER.apt-cache shows reverse dependency of VLCPress SPACE to view the next pages. You also will see forward dependencies.

Note: If you want to see the reverse dependency tree only, you can use the following syntax:

apt-cache rdepends vlc

Method 04: Using Graphviz to Check Dependency Tree in Ubuntu

Graphviz is an open-source software tool for creating diagrams, graphs, and visual representations of various structures, including dependency trees. Technically, it provides a set of tools and libraries for rendering graph-based data into visual formats, such as images or diagrams. To use Graphviz to view a dependency tree, you’ll typically follow these steps:

Step 01: Install Graphviz on Ubuntu

Graphviz is usually not preinstalled. So, you have to install it first in order to use it. Follow the steps to install Graphviz in your Ubuntu:

Steps to Follow >

➊ Open the Ubuntu terminal. You can press CTRL+ALT+T.

➋ Type the command:

sudo apt install -y graphviz
EXPLANATION
  • sudo: Enables administrative permissions.
  • apt: Calls the apt package manager.
  • install: Command used to install packages using apt.
  • -y: Automatically answer YES to all confirmation prompts.
  • graphviz: Package name.

➌ Enter the user password if asked.

➍ Press ENTER.apt installing graphviz in ubuntuThe above command will install Graphviz in your Ubuntu.

Step 02: Generate and Preview Dependency Tree in Ubuntu

Before you can visualize a dependency tree, you need to create a file that represents the tree structure. However, you can use various tools, such as apt-rdepends, debtree, or apt-cache, to generate a text-based representation of the dependency tree. I’ll show you that using debtree in the below steps:

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Type the below command:

debtree vlc | dot > vlctree.dot
EXPLANATION
  • debtree: Command to generate a textual representation of dependencies of a mentioned package.
  • vlc: Package name.
  • | (Piping Symbol): Transfers the output of a command as the input of the next command.
  • dot: Component of Graphviz that converts the textual representation of dependencies into a graphical format
  • > (Output Ridirect): Command to redirect the output generated by a command to a file.
  • dot: Redirected filename.

➌ Press ENTER.generating dot file of VLC player's apt dependency treeThis command will build the dependency tree of VLC and redirect it into a DOT file named vlctree.dot in the current directory.

➍ Now, type the following command to preview the dependency tree:

dotty vlctree.dot
EXPLANATION
  • dotty: Command to launch the Graphviz interactive graph visualization tool.
  • dot: The DOT file that you want to visualize using dotty.
pictorial visualization of VLC apt dependency treeThe above command will preview the graphical structure of vlctree.dot which actually contains the dependency tree information of VLC.

Note: If you want to save the graph file as a PNG format image for later inspection, you can use this command:

dot -Tpng -o <depimage.png> <filename.dot>

Replace <filename.dot> with the dot file name you used in Step. It will generate an image named depimage.png in your current working directory.

Comparative Analysis of Methods

I’ve shown four ways to check apt dependency tree in Ubuntu. You might be confused to decide which one suits you the best. Here’s a comparison between the methods provided to give you an overview of the pros and cons.

Methods Pros Cons
Method 1
  • Automatically identifies all nested dependencies.
  • List the dependencies in a recursive format.
  • Has option to show reverse dependency tree.
  • Integrates with and works in conjunction with the APT package manager, making it a reliable choice.
  • Lacks advanced filtering options to refine search results. This can make it less suitable for complex queries.
Method 2
  • It generates visually appealing graph data that makes it easier to understand complex dependencies.
  • Has filtering options such as direct dependencies, suggested, recommended, etc.
  • Has no option to show reverse dependency tree.
  • It is an external tool and may need to be installed separately.
Method 3
  • Provides detailed information about packages available in the package repositories.
  • Can display reverse dependencies.
  • It provides text-based output, which may not be visually intuitive.
Method 4
  • Can generate visually appealing diagrams that help users understand complex relationships.
  • It supports various output formats, such as PNG, PDF, SVG, and more.
  • Allows users to control the layout, style and appearance of generated graphs.
  • It is an external tool and may need to be installed separately.
  • It doesn’t provide detailed textual information about packages, versions, or descriptions.

If you need a quick exploration of a package dependency tree, Method 1 is a suitable choice. In case of acquiring text information of reverse dependency, you can use Method 3. But if you prefer graphical data and advanced filtering options for in-depth analysis of package dependency trees, Method 2 is a good choice. However, when you need a visual understanding of dependencies, you should use Method 4.

Common Challenges That May Arise

Generating a dependency tree in Ubuntu can be a useful task for understanding package dependencies. However, several common challenges may arise during this process:

  • Multiple Dependency Structures: Some packages have multiple layers of dependencies. This can make the resulting dependency tree large and challenging to visualize or interpret.
  • Missing or Unavailable Packages: Dependency trees rely on package information in the package repositories. If a package’s dependency information is not available in the configured repositories, it can result in generating an inaccurate
  • Outdated Package Information: If the package information on your system is outdated, the generated dependency tree may not reflect the current state of the repositories.
  • Dependency Loop Detection: Dependency loops occur when packages have circular dependencies, which can make it challenging to determine a clear order of the dependency tree.

To mitigate these challenges, it’s essential to keep your package repositories up to date and use reliable tools for dependency analysis.

Install Debtree in Ubuntu

Debtree is a command-line tool to generate a visual representation of the dependency tree for a specified Debian package. As it is usually not preinstalled, first you have to install it. Follow the steps to install debtree in your Ubuntu:

Steps to Follow >

➊ Open the Ubuntu terminal. You can press CTRL+ALT+T.

➋ Type the command:

sudo apt install debtree
EXPLANATION
  • sudo: Enables administrative permissions.
  • apt: Calls the apt package manager.
  • vlc: Package name.

➌ Enter the user password if asked.

➍ Press ENTER.apt installs debtree in ubuntuNow, the above command will install Debtree in your Ubuntu.

Conclusion

The Dependency tree helps package managers to automate the process of resolving complex dependencies and provides users with a consistent and reliable system. It is a powerful tool for representing and understanding the relationships of dependencies within a package. However, you should keep your repository up to date and use softwares form trusted source to get the accurate track of dependency tree of the package.

People Also Ask

What are apt dependencies?

APT dependencies are prerequisite packages for the successful installation of a package using APT in Linux. For example, if you want to install the VLC media player on Ubuntu, APT will install some additional packages like libc6 and vlc bin, libcrypt1 in addition to the primary “vlc” package.

How do I find apt dependencies?
To find apt dependencies, run the command apt-cache show <package name>. If you want both the forward and reverse dependency information, you can use apt-cache showpkg <package name>. In case you want to list all the dependencies in a recursive manner, you have to use apt-rdepends <package name>. Replace <package name> with the actual package name in the commands.
What is dependency tree in Linux?
Dependency tree is the hierarchical representation of dependencies that exist between software packages on a Linux distribution. It visualizes which packages depend on others to function properly.
Does apt install dependencies?
Yes, APT (Advanced Package Tool) is a high-level package management tool for Debian-based Linux distributions that can install dependencies automatically. The command for installing a package with all its dependencies using apt is sudo apt install <package name>. Use the actual name of the package instead of <package name> in the mentioned command.

Related Articles


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

4.9/5 - (8 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

Leave a Comment