Skip to content

Package Management

Package managers solve the problem of software distribution and dependency tracking at scale:

Without a package managerWith a package manager
Manually download tarballs; build from sourceapt install nginx - done
Manually track and update each dependencyDependencies resolved automatically
No record of what’s installed or whyFull audit: who installed what, when
Remove software by deleting files (hoping you get them all)apt remove removes exactly the right files
No integrity verificationChecksums and GPG signatures verified on every install

TypeDescription
BinaryPre-compiled; architecture-specific (amd64, arm64). Ready to run; most common.
SourceCode + build instructions; architecture-independent. Reproducible builds.
Architecture-independentScripts, docs, configs; no compiled code. Runs on any arch.
Meta-packageNo files itself; just dependency declarations. Installs a whole ecosystem (e.g., ubuntu-desktop).

Debian familyRPM family
DistrosDebian, Ubuntu, Mint, Raspberry Pi OSRHEL, CentOS, Fedora, SUSE, Rocky, AlmaLinux
Low-level tooldpkgrpm
High-level toolapt (also apt-get, apt-cache)dnf (also yum on older systems)
Package format.deb.rpm
Package DB location/var/lib/dpkg//var/lib/rpm/
Repo config/etc/apt/sources.list, /etc/apt/sources.list.d//etc/yum.repos.d/*.repo

Package manager levels


<name>_<version>-<revision>_<architecture>.deb
logrotate_3.14.0-4_amd64.deb

Note: 64-bit x86 is called amd64 in Debian/Ubuntu (not x86_64).

dpkg installs, removes, and queries .deb files directly. It does not resolve dependencies.

Terminal window
# Install a .deb file
sudo dpkg -i package.deb
# Remove package (keep config files)
sudo dpkg -r package
# Purge package (remove config files too)
sudo dpkg -P package
# List all installed packages
dpkg -l
# Check if a specific package is installed and get version
dpkg -s wget
# List files installed by a package
dpkg -L wget
# Show which package owns a file
dpkg -S /usr/bin/wget
# Inspect a .deb file without installing
dpkg -I package.deb # package info/metadata
dpkg -c package.deb # list contents
# Verify integrity of installed packages
dpkg -V
dpkg -V package # verify one package

apt wraps dpkg with dependency resolution, repository management, and network downloads.

Terminal window
# Update the local package index (before install/upgrade)
sudo apt update
# Install a package (and its dependencies)
sudo apt install nginx
# Install a specific version
sudo apt install nginx=1.18.0-0ubuntu1
# Remove (keep config files)
sudo apt remove nginx
# Purge (remove + config files)
sudo apt purge nginx
# or:
sudo apt remove --purge nginx
# Upgrade all installed packages
sudo apt upgrade
# Upgrade + remove obsolete packages and add new dependencies
sudo apt full-upgrade # safe, interactive
sudo apt dist-upgrade # same thing
# Remove auto-installed packages no longer needed
sudo apt autoremove
# Clean downloaded package cache
sudo apt clean # remove all cached .deb files
sudo apt autoclean # remove only outdated cached files
# Search for a package
apt search keyword
apt-cache search keyword
# Show package information
apt show nginx
apt-cache show nginx
apt-cache showpkg nginx # detailed with reverse deps
# List all versions available
apt-cache madison nginx
# Find which package provides a specific file/command
apt-file search /usr/bin/wget # requires: sudo apt install apt-file; apt-file update
# List direct dependencies of a package
apt-cache depends nginx

Binary:

<name>-<version>-<release>.<distro>.<arch>.rpm
sed-4.5-2.el8.x86_64.rpm

Source: same format but ends in .src.rpm

Terminal window
# Install a package file (verbose + progress bars)
sudo rpm -ivh package.rpm
# Upgrade (install if not present, upgrade if present)
sudo rpm -Uvh package.rpm
# Uninstall (erase) a package
sudo rpm -e package-name # note: package NAME, not filename
# Test uninstall without doing it
sudo rpm --test -e package-name
# Freshen: upgrade only already-installed packages
sudo rpm -Fvh *.rpm

All query options start with -q:

QueryCommand
Is this package installed? What version?rpm -q bash
Which package owns this file?rpm -qf /bin/bash
What files did this package install?rpm -ql bash
Package info (description, size, etc.)rpm -qi bash
Query against a .rpm file (not the DB)rpm -qip package.rpm
List ALL installed packagesrpm -qa
What does this package require?rpm -q --requires bash
What package provides this library?rpm -q --whatprovides libc.so.6
Terminal window
rpm -V package # verify one package
rpm -Va # verify all packages
# Output key: each character is a field that differs from the installed DB
# S=filesize, M=mode (permissions), 5=MD5 checksum, D=device, L=readLink
# U=user owner, G=group owner, T=mtime
# Example: S.5....T. c /etc/logrotate.conf (size, md5, mtime differ; it's a config file)

No output = everything OK.

Extracting Files from an RPM (Without Installing)

Section titled “Extracting Files from an RPM (Without Installing)”
Terminal window
# Method 1: rpm2cpio (older, classic)
rpm2cpio package.rpm | cpio --extract --make-directories -v
# Extract just one file
rpm2cpio package.rpm | cpio -ivd ./usr/bin/bash
# Method 2: rpm2archive (newer)
rpm2archive package.rpm # creates package.rpm.tgz
cat package.rpm | rpm2archive - | tar -xvz # one-liner to extract
# List files in an .rpm before extracting
rpm -qilp package.rpm

dnf replaced yum as the default on RHEL 8, Fedora. Most yum commands still work with dnf.

Terminal window
# View configured repos
sudo dnf repolist
# Repo config files location
ls /etc/yum.repos.d/
# Sample .repo file format
# [repo-name]
# name=My Repository
# baseurl=https://example.com/rpms/
# enabled=1
# gpgcheck=1
# gpgkey=https://example.com/RPM-GPG-KEY
Terminal window
# Update package index
sudo dnf check-update
# Install
sudo dnf install nginx
sudo dnf localinstall package.rpm # install from a local file
sudo dnf groupinstall "Development Tools"
# Remove
sudo dnf remove nginx
# Update
sudo dnf update # update all packages
sudo dnf update nginx # update one package
# Search and info
dnf search keyword
dnf info nginx
dnf list installed
dnf list available
dnf list updates
# Dependency queries
dnf provides /usr/bin/wget # what package gives this file?
dnf repoquery --requires nginx # what does nginx require?
dnf repoquery --whatrequires nginx # what requires nginx?
# Groups
dnf grouplist
dnf groupinfo "Development Tools"
dnf groupinstall "Development Tools"
# History (can undo!)
sudo dnf history
sudo dnf history info 5 # details of transaction #5
sudo dnf history undo 5 # undo transaction #5
# Maintenance
sudo dnf autoremove # remove unused dependencies
sudo dnf clean all # clean all cached data
sudo dnf clean packages # remove only cached packages
# Download without installing
sudo dnf install --downloadonly --downloaddir=/tmp nginx

Terminal window
# List available kernels
apt search linux-image
# Install a new kernel (apt does NOT remove the old one)
sudo apt install linux-image-6.5.0-18-generic
# Old kernel stays; GRUB shows both; remove when confident
sudo apt remove linux-image-OLD-VERSION
sudo apt autoremove # also removes related headers/modules
sudo update-grub
Terminal window
# Use -i (install), NOT -U (upgrade) for kernels
# -U would remove the old kernel; -i keeps it alongside
sudo rpm -ivh kernel-6.x.x-x.el9.x86_64.rpm
# OR
sudo dnf install kernel-6.x.x # dnf also keeps old kernel (by policy)
# Remove older kernels
sudo dnf remove --oldinstallonly # keeps the newest N kernels (set in dnf.conf)

TaskDebian/UbuntuRHEL/Fedora
Update repo indexapt updatednf check-update
Install packageapt install PKGdnf install PKG
Remove packageapt remove PKGdnf remove PKG
Purge + configapt purge PKGdnf remove PKG (no config)
List installeddpkg -lrpm -qa
Searchapt search KWdnf search KW
Package of filedpkg -S /path/filerpm -qf /path/file
Files in packagedpkg -L PKGrpm -ql PKG
Package infoapt show PKGdnf info PKG
Update allapt upgradednf update
Clean cacheapt cleandnf clean all
Unneeded depsapt autoremovednf autoremove