Packages

Files, plus a record of what they need and where they went

nginx_1.24.0-2ubuntu7.19_amd64.deb525 KB download, 1.3 MB installedfiles/usr/sbin/nginx/usr/share/man/man8/nginx.8.gz/etc/nginx/ (from nginx-common)/usr/lib/systemd/system/nginx.serviceunpacked into the tree, each onerecorded so it can be removedmetadataVersion: 1.24.0-2ubuntu7.19Depends: libc6 (>= 2.34), libssl3t64, iproute2, nginx-common (= ...)Architecture: amd64scripts and signaturepostinst: create the user, start the servicesigned by the distribution’s keyA package is an archive of files plus metadata: its version, what it needs, and scripts to run around install.The package manager keeps a database of every file each package put on disk, so it can upgrade or remove them cleanly and tell youwho owns any file: dpkg -S /usr/bin/ls answers coreutils. Debian and Ubuntu use .deb files; Red Hat, Fedora, AlmaLinux and SUSEuse .rpm. The idea is identical.

A package holds files, metadata such as version and dependencies, install scripts and a signature.

Repositories

A signed index the package manager trusts

repositoryarchive.ubuntu.compublished thereRelease signed list of indexesPackages every package, version, depspool/ the .deb filesapt updatesignature checkedlocal index/var/lib/apt/listsapt installinstallresolve, download, verifyTypes: debURIs: http://archive.ubuntu.com/ubuntu/Suites: noble noble-updates noble-backportsSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg/etc/apt/sources.list.d/ubuntu.sourcesRHEL: /etc/yum.repos.d/*.repo, with baseurl= and gpgkey=A repository is a signed index of packages; apt and dnf trust only what the configured keys have signed.apt update downloads the indexes, it installs nothing; apt upgrade then installs newer versions. dnf refreshes its metadata on its own.Adding a repository means adding its address and its key: from then on, that publisher can put software on your machine as root.

A repository publishes signed indexes and packages; apt update fetches the indexes and checks the signature.

Dependencies

Ask for one package, receive the tree it needs

nginxwhat you asked fornginx-commoniproute2libssl3t64libbpf1libatm1t64libc6, zlib1g, libpcre2-8-0,libcrypt1: already installed$ apt-get install --simulate nginx0 upgraded, 5 newly installed, 0 to removepurple: to install · grey: already thereAsk for one package and the manager works out the tree it needs, installing only what is missing.This is the job that makes package managers worth having: nginx needs nine libraries and tools, and this server lacked five. Removenginx later and apt autoremove clears the ones nothing else needs. Real output from an Ubuntu 24.04 server.

The package manager resolves dependencies and installs only the missing ones; autoremove clears them later.

apt and dnf

Two families of tools, the same ten verbs

TaskDebian, Ubuntu: apt, dpkgRHEL, AlmaLinux, Fedora: dnf, rpminstallapt install nginxdnf install nginxremoveapt remove nginxdnf remove nginxupdate everythingapt update && apt upgradednf upgradesearchapt search nginxdnf search nginxdetailsapt show nginxdnf info nginxinstalled?dpkg -l nginxrpm -q nginxwho owns a filedpkg -S /usr/sbin/nginxrpm -qf /usr/sbin/nginxfiles of a packagedpkg -L nginxrpm -ql nginxa local fileapt install ./x.debdnf install ./x.rpmhistory, undo/var/log/apt/history.logdnf history; dnf history undo 7Two families, the same verbs: apt and dpkg on Debian and Ubuntu, dnf and rpm on the Red Hat family.apt and dnf are the high-level tools: they talk to repositories and resolve dependencies. dpkg and rpm work on one package file andthe local database, and refuse when something is missing. Use the high-level tool even for a local file (dnf install ./x.rpm),so its dependencies come from the repositories. yum on RHEL 10 is a name for dnf.

apt and dpkg on Debian and Ubuntu, dnf and rpm on Red Hat: high-level tools resolve, low-level ones query.

apt and dnf · Going deeper · 1 of 3

Five lines in /etc/yum.repos.d add a repository

# cat /etc/yum.repos.d/internal.repo[internal-baseos]name=Internal BaseOS mirrorbaseurl=http://repo.lab.example/rhel10/BaseOSenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release# dnf repolistrepo id repo nameinternal-baseos Internal BaseOS mirrorinternal-appstream Internal AppStream mirror1One section per repository[id], then key=value lines2baseurl: where the packages arehttp, https, ftp or file://3gpgcheck=1, with its keynever turn signatures off4BaseOS and AppStreamRHEL’s two main repositories5dnf config-manager --add-repo URLwrites this file for youOn RHEL a repository is a few lines in /etc/yum.repos.d; the exam gives you a URL and expects exactly this.BaseOS holds the core operating system and AppStream the applications, languages and databases. dnf repolist confirms therepositories work; dnf clean all clears stale metadata after a change.

A .repo file names the repository, its baseurl and its GPG key; BaseOS and AppStream are RHEL’s two main ones.

apt and dnf · Going deeper · 2 of 3

Desktop apps from their own remotes, in a sandbox

the host: RHEL 10system packages from dnfkernel, libraries, servicesFlatpakorg.gnome.Calculatorapp, sandboxedorg.gnome.Platformshared runtimeflatpak installa remoteFlathub, or Red Hat’s$ flatpak remote-add --if-not-exists \ flathub https://dl.flathub.org/repo/...$ flatpak install flathub org.gnome.Calculator$ flatpak list --app$ flatpak run org.gnome.Calculator$ flatpak uninstall org.gnome.Calculator$ flatpak remotesFlatpak installs desktop applications from their own remotes, each sandboxed, sharing runtimes, apart from the system.An app brings the libraries it needs as a runtime, so it can be newer than the distribution and cannot break system packages. It seesonly what its permissions allow. RHEL 10 ships Flatpak and its exam asks you to add a remote and install from it; Ubuntu ships Snapfor the same purpose. Servers rarely need either.

Flatpak installs sandboxed applications and shared runtimes from remotes such as Flathub, separately from system packages.

apt and dnf · Going deeper · 3 of 3

Compile it yourself only when there is no package

./configure --prefix=/usr/localchecks the system, writes a Makefilemakecompilessudo make installcopies into /usr/local/bin, lib, shareWhat the package manager would have done, and this did not:✗ recorded each file, for removal✗ installed the build tools and libraries✗ delivered security fixes✗ checked a signatureBuilding from source is the last resort: it works, and nothing will ever update or remove it for you.If you must, install into /usr/local or /opt so it cannot clash with packaged files, keep the build directory, and prefer making apackage (or a container image). Install the compiler first: build-essential on Ubuntu, dnf group install "Development Tools" on RHEL.

configure, make and make install build into /usr/local, with no tracking, dependencies or security updates.

Updates

Patch on a schedule, and keep the last kernel

Kernels are installed side by side, never replaced6.12.0-55.el10kept as a fallback6.12.0-55.9.1.el10kept as a fallback6.12.0-55.12.1.el10newest: boots by defaultdnf keeps 3 (installonly_limit)version numbers are examplesNeedHowsecurity fixes onlydnf upgrade --security · apt with unattended-upgradesautomatic updatesdnf-automatic.timer · unattended-upgrades (on by default on Ubuntu)is a reboot needed?dnf needs-restarting -r · /var/run/reboot-requiredhold one versiondnf versionlock add · apt-mark holdPatch on a schedule, reboot for new kernels, and keep the previous kernel in case the new one fails.A library update needs the programs using it restarted, and a kernel update needs a reboot, to take effect. If a new kernel will notboot, pick the older one from the GRUB menu and investigate from there.

Kernels install side by side; libraries need restarts and kernels need reboots; dnf-automatic or unattended-upgrades automate it.

Lab

Install, trace and remove on both families

$ apt-get install --simulate nginx | tail -11Inst nginx (1.24.0-2ubuntu7.19 Ubuntu:24.04/noble-updates ...)$ sudo apt install -y nginx2$ dpkg -S /usr/sbin/nginx3nginx: /usr/sbin/nginx$ dpkg -L nginx-common | grep conf$ | head -24/etc/nginx/nginx.conf/etc/nginx/fastcgi.conf$ sudo apt remove nginx && sudo apt autoremove51See the plan first--simulate changes nothing2Install itdependencies come along3Who owns this file?the reverse question4What did it install?its configuration files5Remove it cleanlyand the libraries nobody needsLab: install, query and remove on both families, add a repository, and install a Flatpak.An Ubuntu VM and an AlmaLinux or Rocky Linux 10 VM. Press the down arrow for the steps.

apt and dnf side by side: simulate, install, find a file’s owner, add a repository by hand, install a Flatpak, remove cleanly.

Lab · Going deeper

Install, trace and remove software on both families

Do steps 1 to 4 on Ubuntu and 5 to 8 on AlmaLinux or Rocky Linux 10. Both are free and close to what the exams use.

Steps

  1. Read the plan. apt-get install --simulate nginx. Which packages are new? Compare with apt-cache depends nginx.
  2. Install and trace. sudo apt install nginx; dpkg -L nginx; dpkg -S /etc/nginx/nginx.conf; systemctl status nginx.
  3. Find the sources. cat /etc/apt/sources.list.d/ubuntu.sources. Name the suites and the key file. Run apt policy nginx to see which repository won.
  4. Remove it. sudo apt purge nginx nginx-common; sudo apt autoremove. What is the difference between remove and purge?
  5. Same on RHEL. sudo dnf install nginx; rpm -qf /usr/sbin/nginx; rpm -ql nginx | head; dnf history; dnf history undo last.
  6. Add a repository. Write /etc/yum.repos.d/local.repo pointing at a mounted install image (baseurl=file:///mnt/BaseOS, gpgcheck=1 with the key in /etc/pki/rpm-gpg). Check with dnf repolist.
  7. Install a local file. dnf download tree; sudo dnf install ./tree-*.rpm; rpm -qi tree. Then rpm -e tree.
  8. Flatpak. flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo; flatpak install flathub org.gnome.Calculator; flatpak list; flatpak uninstall it.
Check: You can name the package that owns any file you are shown, on either family, and dnf repolist lists the repository you wrote by hand.

Lesson complete

You finished “Installing software”

Nicely done.

Open in a new tab