Package Dependency Management

Almost every package on Ubuntu requires other packages to function. When you install nginx, apt silently installs 10–15 dependency packages. When you later try to remove one of those dependencies, apt may refuse. Understanding how dependency resolution works gives you control over what is installed and why.

How APT resolves dependencies

When you run sudo apt install package, APT reads the package metadata and builds a dependency graph. It then calculates the minimum set of packages that need to be installed to satisfy all dependencies, downloads them in the correct order, and installs them.

apt install php8.3-fpm
      │
      ├── Depends: php8.3-common (>= 8.3)
      │     ├── Depends: libssl3
      │     └── Depends: libpcre2-8-0
      ├── Depends: php8.3-cli
      │     └── Depends: php8.3-common (already in tree)
      └── Recommends: php8.3-opcache

All must be installed for php8.3-fpm to work correctly.

Inspecting dependencies

# Show all dependencies of a package
apt-cache depends nginx

# Show only required deps (not Recommends/Suggests)
apt-cache depends --important nginx

# Show reverse dependencies: what packages depend on nginx
apt-cache rdepends nginx

# Show only installed packages that depend on nginx
apt-cache rdepends --installed nginx

# Show the full dependency tree
apt-cache depends --recurse nginx | grep "Depends:" | sort -u | head -20

# Show what packages will be installed with a package
apt-get install --dry-run nginx

Example: depends output

nginx
  Depends: nginx-core | nginx-full | nginx-light | nginx-extras
  Depends: iproute2
  PreDepends: init-system-helpers
  Recommends: nginx-common
  Suggests: fcgiwrap

Dependency types

TypeMeaningapt installs automatically?
DependsMust be installed for the package to workYes
Pre-DependsMust be installed and configured before this packageYes
RecommendsStrongly suggested; usually installed with the packageYes (default)
SuggestsOptional enhancement; rarely neededNo
ConflictsCannot be installed alongside this packageN/A (blocks install)
ReplacesReplaces files from another packageN/A (handles file conflicts)
BreaksThis package breaks the listed package if both installedN/A
# Install without Recommends (leaner install for servers)
sudo apt install --no-install-recommends nginx

# Show which packages are installed as automatic (dependency) packages
apt-mark showmanual     # Explicitly installed by user
apt-mark showauto       # Installed as a dependency

Pinning package versions

Pinning locks a package to a specific version to prevent automatic upgrades. This is useful when a newer version of a package breaks your application.

# Hold a package at its current version
sudo apt-mark hold nginx

# See held packages
apt-mark showhold

# Release the hold
sudo apt-mark unhold nginx

# Pin to a specific version using apt preferences
sudo nano /etc/apt/preferences.d/nginx-pin

/etc/apt/preferences.d/nginx-pin content

Package: nginx
Pin: version 1.24.*
Pin-Priority: 1001
# Verify the pin
apt-cache policy nginx

Resolving conflicts

# See what is conflicting
apt-cache show package1 | grep -E "Conflicts|Breaks"

# When apt refuses to install due to conflicts, simulate to see why
apt-get install --simulate package1 package2

# Use aptitude for smarter conflict resolution
sudo apt install aptitude
sudo aptitude install conflicting-package
# aptitude will suggest multiple solutions; review and choose

Conclusion

APT dependency management is mostly automatic, but knowing how to inspect it with apt-cache depends and apt-cache rdepends helps when you need to understand why removing a package will remove others, or why installing a new package conflicts with something you already have. Use apt-mark hold to prevent specific packages from being upgraded when a new version breaks your application.

FAQ

Is Package Dependency Management important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support