Package Management | Linux - Wyatt's Notes
Package Formats
Section titled “Package Formats”A Linux package is an archive containing compiled software, configuration files, metadata (version, Description, dependencies), and install/uninstall scripts. Two dominant package formats exist:
| Format | Specification | Distributions | Extension |
|---|---|---|---|
| DEB | Debian Policy | Debian, Ubuntu, Mint, Proxmox | .deb |
| RPM | RPM Specification | RHEL, Fedora, CentOS, SUSE, OpenMandriva | .rpm |
Package Anatomy
Section titled “Package Anatomy”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]## Inspect a DEB package without installingdpkg-deb -I package.deb # control infodpkg-deb -c package.deb # list files
## Inspect an RPM package without installingrpm -qip package.rpm # inforpm -qlp package.rpm # list filesrpm -q --scripts package.rpm # install/remove scriptsAPT (Debian/Ubuntu)
Section titled “APT (Debian/Ubuntu)”APT (Advanced Package Tool) is the high-level package manager for .deb distributions. It handles Dependency resolution, repository management, and package installation.
APT Commands
Section titled “APT Commands”# Update package index (always run before installing)apt update
# Upgrade all packagesapt upgrade # upgrade installed packagesapt full-upgrade # handle dependency changes (recommended)apt dist-upgrade # alias for full-upgrade
# Install packagesapt install nginxapt install nginx=1.24.0-1 # specific versionapt install --no-install-recommends nginx # skip recommended packages
# Remove packagesapt remove nginx # remove package, keep configapt purge nginx # remove package and config filesapt autoremove # remove orphaned dependencies
# Searchapt search webserverapt list --installed # list installed packagesapt list --upgradable # list upgradable packages
# Show package informationapt show nginx
# Download without installingapt download nginxapt source nginx # download source package
# Fix broken dependenciesapt --fix-broken install
# Hold/unhold packages (prevent upgrades)apt-mark hold package_nameapt-mark unhold package_nameapt-mark showhold
# Check why a package is installedapt rdepends package_name # reverse dependenciesaptitude why package_name # reason for installation (aptitude)APT Sources Configuration
Section titled “APT Sources Configuration”# /etc/apt/sources.list (traditional format)deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmwaredeb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmwaredeb 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.listdeb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stableAPT Pinning
Section titled “APT Pinning”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 Range | Effect |
|---|---|
| 0 | Never install (used for blocking) |
| 1-99 | Install only if no higher-priority version exists |
| 100-499 | Install only if no installed version exists |
| 500 | Default priority (any version from this source) |
| 990 | Prefer over default priority |
| 1001 | Install even if downgrading |
Package: *Pin: origin download.docker.comPin-Priority: 900
# Pin specific package to specific versionPackage: nginxPin: version 1.24.*Pin-Priority: 1001
# Pin a package to prevent installationPackage: systemd-resolvedPin: release *Pin-Priority: -1dpkg — Low-Level Package Manager
Section titled “dpkg — Low-Level Package Manager”# Install a .deb filedpkg -i package.deb
# Remove a packagedpkg -r package_name
# List installed packagesdpkg -ldpkg -l | grep nginx
# List files installed by a packagedpkg -L package_name
# Find which package owns a filedpkg -S /usr/bin/nginx
# Configure unpacked packagesdpkg --configure -a # configure all pending packages
# Package statusdpkg -s package_name # show status and detailsdpkg-query -W -f="${Package} ${Version}\n' # custom formatDNF (RHEL/Fedora)
Section titled “DNF (RHEL/Fedora)”DNF (Dandified YUM) is the package manager for RPM-based distributions, succeeding YUM with better Dependency resolution, faster performance, and a plugin architecture.
DNF Commands
Section titled “DNF Commands”# Update package indexdnf check-update
# Upgrade all packagesdnf upgrade
# Install packagesdnf install nginxdnf install nginx-1.24.0 # specific version
# Remove packagesdnf remove nginxdnf autoremove # remove orphaned dependencies
# Searchdnf search webserverdnf list installeddnf list availablednf list updates
# Package informationdnf info nginx
# Downloaddnf download nginx
# History (track transactions)dnf history listdnf history undo 15 # undo transaction 15dnf history redo 15 # redo transaction 15
# Group managementdnf group listdnf group install "Development Tools"dnf group info "Development Tools"
# Module streams (RHEL 8+/Fedora)dnf module listdnf module enable nodejs:18dnf module install nodejs:18/default
# Lock packages (prevent upgrades)dnf versionlock add nginxdnf versionlock listdnf versionlock delete nginx
# Clean cachednf clean all
# Repository managementdnf repolistdnf repolist enableddnf repolist allDNF Repository Configuration
Section titled “DNF Repository Configuration”[nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/rhel/9/x86_64/enabled=1gpgcheck=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=truerpm — Low-Level Package Manager
Section titled “rpm — Low-Level Package Manager”# Install an RPMrpm -ivh package.rpm
# Upgraderpm -Uvh package.rpm
# Query installed packagesrpm -qarpm -qa | grep nginx
# Query package inforpm -qi nginx
# List files in installed packagerpm -ql nginx
# List files in RPM filerpm -qlp package.rpm
# Find which package owns a filerpm -qf /usr/bin/nginx
# Verify package (check file checksums, permissions)rpm -V nginxrpm -Va # verify all packages
# Check package dependenciesrpm -qR nginx # requires (dependencies)rpm -q --whatprovides libssl.so.3RPM Verification
Section titled “RPM Verification”# Verify a specific packagerpm -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 packagesrpm -Va | grep '^..5' # find all files with changed checksumspacman (Arch Linux)
Section titled “pacman (Arch Linux)”Pacman is the package manager for Arch Linux and its derivatives. It is simple, fast, and follows a Rolling release model.
pacman Commands
Section titled “pacman Commands”# Update package database and upgrade all packagespacman -Syu # sync database, then upgradepacman -Sy # sync database onlypacman -Su # upgrade only (use after -Sy)
# Install packagespacman -S nginxpacman -S --noconfirm nginx # skip confirmation
# Remove packagespacman -R nginx # remove, keep dependenciespacman -Rs nginx # remove and dependencies not needed by otherspacman -Rns nginx # remove, dependencies, and config files
# Searchpacman -Ss nginx # search remote repositoriespacman -Qs nginx # search installed packagespacman -Qi nginx # package info (installed)pacman -Si nginx # package info (remote)
# List filespacman -Ql nginx # files from installed packagepacman -Qo /usr/bin/nginx # which package owns this file
# Downloadpacman -Sw nginx # download without installing
# Clear cachepacman -Sc # keep latest versionpacman -Scc # remove all cached packages
# Dependency treepactree nginx # dependency treepactree -r nginx # reverse dependency tree
# Databasepacman -Q # list installed packagespacman -Qm # list foreign/AUR packagespacman -Qe # list explicitly installedpacman -Qdt # list orphaned packages
# Remove orphanspacman -Rns $(pacman -Qdtq)AUR — Arch User Repository
Section titled “AUR — Arch User Repository”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.
# Using an AUR helper (e.g., paru)paru -S package_name # install from AURparu -Syu # update including AUR packagesparu -Ss search_term # search AUR
# Manual AUR installationgit clone https://aur.archlinux.org/packages/examplecd packagemakepkg -si # build and installIntuition
Section titled “Intuition”Processes are programs in execution, each with its own memory space and priority. Systemd manages the lifecycle of services, starting them at boot and restarting them if they fail. Understanding process states (running, sleeping, stopped, zombie) helps you diagnose why a service is not responding. Signals like SIGTERM and SIGKILL provide graceful and forceful ways to control processes.