Skip to content

Linux Foundations / Manage a Linux host ยท Step 18 of 50

Lesson: Package DependenciesSwitch
โ† Linux Foundations

System administration

Package Dependencies

Why packages need other packages, how shared libraries fit in, and what to do when something is missing.

Few programs work entirely on their own. A web client may need a library for encryption, another for compression, and the C library for basic functions. These requirements are dependencies.

Why dependencies exist

Programs share code through shared libraries, files whose names usually contain .so. One copy on disk serves many programs, and a security fix to the library reaches all of them once they are restarted.

The ldd command shows which libraries a program loads:

$ ldd /bin/ls
        linux-vdso.so.1 (0x00007ffd...)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6

Your paths and list will differ. Run ldd only on programs you trust, because in some cases it can execute code from the file.

Declared dependencies

Each package lists what it needs, often with a minimum version. On Debian based systems:

$ apt-cache depends curl
curl
  Depends: libc6
  Depends: libcurl4
  Depends: zlib1g

The output is shortened, and exact names differ between releases (newer ones show libcurl4t64). On RPM systems you can run rpm -qR curl for an installed package, or dnf repoquery --requires curl.

Debian also has weaker relations. Recommends are installed by default but can be left out. Suggests are optional extras that are not installed by default.

Chains and conflicts

Dependencies have their own dependencies, so installing one program may pull in many packages. Some packages also conflict: they cannot be installed together, for instance because they provide the same file.

High level tools such as apt and dnf work out the whole set, download it and install it in a valid order. The low level tools dpkg and rpm check dependencies but do not download anything.

When something is missing

Installing a lone package file with dpkg can leave it unconfigured:

$ sudo dpkg -i tool.deb
dpkg: dependency problems prevent configuration of tool

On Debian based systems, this asks APT to repair the situation by installing what is missing, or sometimes by removing the broken package:

$ sudo apt --fix-broken install

Read the proposed changes before you answer yes. Do not use options that force installation past dependency errors. They leave you with software that may not start.

When you remove a program, its dependencies can stay behind. sudo apt autoremove or sudo dnf autoremove removes ones that nothing needs any more. Again, check the list first.

Try it

Pick a program and compare the two views:

$ ldd "$(command -v bash)"
$ apt-cache depends bash     # Debian, Ubuntu
$ rpm -qR bash               # Fedora, RHEL

Match a library from the first output to a requirement in the second. There is more to explore in the packages, disk and FHS lab.

Check your understanding

Package Dependencies

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.