Skip to content

Package Management

A Linux package is an archive containing compiled software, configuration files, metadata (version, Description, dependencies), and install/uninstall scripts. Two dominant package formats exist:

FormatSpecificationDistributionsExtension
DEBDebian PolicyDebian, Ubuntu, Mint, Proxmox.deb
RPMRPM SpecificationRHEL, Fedora, CentOS, SUSE, OpenMandriva.rpm

Both formats share similar internal structure:

graph TD
    A[Package Archive] --> B[Control / Metadata]
    A --> C[Payload / Data]
    B --> D[Package name, version, arch]
    B --> E[Dependency list]
    B --> F[Description, maintainer, license]
    B --> G[Install/Remove scripts]
    C --> H[Compiled binaries]
    C --> I[Configuration files]
    C --> J[Documentation]
    C --> K[Systemd unit files]
    C --> L[Man pages]
Terminal window
# Inspect a DEB package without installing
dpkg-deb -I package.deb # control info
dpkg-deb -c package.deb # list files
# Inspect an RPM package without installing
rpm -qip package.rpm # info
rpm -qlp package.rpm # list files
rpm -q --scripts package.rpm # install/remove scripts

APT (Advanced Package Tool) is the high-level package manager for .deb distributions. It handles Dependency resolution, repository management, and package installation.

Terminal window
# Update package index (always run before installing)
apt update
# Upgrade all packages
apt upgrade # upgrade installed packages
apt full-upgrade # handle dependency changes (recommended)
apt dist-upgrade # alias for full-upgrade
# Install packages
apt install nginx
apt install nginx=1.24.0-1 # specific version
apt install --no-install-recommends nginx # skip recommended packages
# Remove packages
apt remove nginx # remove package, keep config
apt purge nginx # remove package and config files
apt autoremove # remove orphaned dependencies
# Search
apt search webserver
apt list --installed # list installed packages
apt list --upgradable # list upgradable packages
# Show package information
apt show nginx
# Download without installing
apt download nginx
apt source nginx # download source package
# Fix broken dependencies
apt --fix-broken install
# Hold/unhold packages (prevent upgrades)
apt-mark hold package_name
apt-mark unhold package_name
apt-mark showhold
# Check why a package is installed
apt rdepends package_name # reverse dependencies
aptitude why package_name # reason for installation (aptitude)
Terminal window
# /etc/apt/sources.list (traditional format)
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# /etc/apt/sources.list.d/ (modern one-per-file format)
# /etc/apt/sources.list.d/docker.list
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable

APT pinning allows you to control which version of a package is installed when multiple sources Provide different versions. Pins have a priority (0-1001):

Priority RangeEffect
0Never install (used for blocking)
1-99Install only if no higher-priority version exists
100-499Install only if no installed version exists
500Default priority (any version from this source)
990Prefer over default priority
1001Install even if downgrading
/etc/apt/preferences.d/docker
Package: *
Pin: origin download.docker.com
Pin-Priority: 900
# Pin specific package to specific version
Package: nginx
Pin: version 1.24.*
Pin-Priority: 1001
# Pin a package to prevent installation
Package: systemd-resolved
Pin: release *
Pin-Priority: -1
Terminal window
# Install a .deb file
dpkg -i package.deb
# Remove a package
dpkg -r package_name
# List installed packages
dpkg -l
dpkg -l | grep nginx
# List files installed by a package
dpkg -L package_name
# Find which package owns a file
dpkg -S /usr/bin/nginx
# Configure unpacked packages
dpkg --configure -a # configure all pending packages
# Package status
dpkg -s package_name # show status and details
dpkg-query -W -f="${Package} ${Version}\n' # custom format

DNF (Dandified YUM) is the package manager for RPM-based distributions, succeeding YUM with better Dependency resolution, faster performance, and a plugin architecture.

Terminal window
# Update package index
dnf check-update
# Upgrade all packages
dnf upgrade
# Install packages
dnf install nginx
dnf install nginx-1.24.0 # specific version
# Remove packages
dnf remove nginx
dnf autoremove # remove orphaned dependencies
# Search
dnf search webserver
dnf list installed
dnf list available
dnf list updates
# Package information
dnf info nginx
# Download
dnf download nginx
# History (track transactions)
dnf history list
dnf history undo 15 # undo transaction 15
dnf history redo 15 # redo transaction 15
# Group management
dnf group list
dnf group install "Development Tools"
dnf group info "Development Tools"
# Module streams (RHEL 8+/Fedora)
dnf module list
dnf module enable nodejs:18
dnf module install nodejs:18/default
# Lock packages (prevent upgrades)
dnf versionlock add nginx
dnf versionlock list
dnf versionlock delete nginx
# Clean cache
dnf clean all
# Repository management
dnf repolist
dnf repolist enabled
dnf repolist all
/etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/rhel/9/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
Terminal window
# Install an RPM
rpm -ivh package.rpm
# Upgrade
rpm -Uvh package.rpm
# Query installed packages
rpm -qa
rpm -qa | grep nginx
# Query package info
rpm -qi nginx
# List files in installed package
rpm -ql nginx
# List files in RPM file
rpm -qlp package.rpm
# Find which package owns a file
rpm -qf /usr/bin/nginx
# Verify package (check file checksums, permissions)
rpm -V nginx
rpm -Va # verify all packages
# Check package dependencies
rpm -qR nginx # requires (dependencies)
rpm -q --whatprovides libssl.so.3
Terminal window
# Verify a specific package
rpm -V nginx
# Output format: each character indicates a test result
# S = file size differs
# 5 = MD5 checksum differs
# T = mtime differs
# D = device major/minor differs
# L = symlink path differs
# U = user ownership differs
# G = group ownership differs
# M = mode (permissions) differs
# ? = unreadable file
# . = test passed
# Verify all installed packages
rpm -Va | grep '^..5' # find all files with changed checksums

Pacman is the package manager for Arch Linux and its derivatives. It is simple, fast, and follows a Rolling release model.

Terminal window
# Update package database and upgrade all packages
pacman -Syu # sync database, then upgrade
pacman -Sy # sync database only
pacman -Su # upgrade only (use after -Sy)
# Install packages
pacman -S nginx
pacman -S --noconfirm nginx # skip confirmation
# Remove packages
pacman -R nginx # remove, keep dependencies
pacman -Rs nginx # remove and dependencies not needed by others
pacman -Rns nginx # remove, dependencies, and config files
# Search
pacman -Ss nginx # search remote repositories
pacman -Qs nginx # search installed packages
pacman -Qi nginx # package info (installed)
pacman -Si nginx # package info (remote)
# List files
pacman -Ql nginx # files from installed package
pacman -Qo /usr/bin/nginx # which package owns this file
# Download
pacman -Sw nginx # download without installing
# Clear cache
pacman -Sc # keep latest version
pacman -Scc # remove all cached packages
# Dependency tree
pactree nginx # dependency tree
pactree -r nginx # reverse dependency tree
# Database
pacman -Q # list installed packages
pacman -Qm # list foreign/AUR packages
pacman -Qe # list explicitly installed
pacman -Qdt # list orphaned packages
# Remove orphans
pacman -Rns $(pacman -Qdtq)

The AUR is a community-maintained repository of PKGBUILD scripts. It is not a binary repository — Packages are built from source on the local machine.

Terminal window
# Using an AUR helper (e.g., paru)
paru -S package_name # install from AUR
paru -Syu # update including AUR packages
paru -Ss search_term # search AUR
# Manual AUR installation
git clone https://aur.archlinux.org/packages/example
cd package
makepkg -si # build and install