12. Package Management
Unlike Windows or macOS, where software is often downloaded via web browsers as unmanaged installers, Linux relies on centralized Package Managers to download, install, update, and remove software securely from cryptographically signed repositories.
12.1 Core Concepts
Section titled “12.1 Core Concepts”- Package: A compressed archive containing pre-compiled binaries, configuration files, and metadata required to install an application.
- Dependency: Software often relies on shared libraries or auxiliary runtimes. Package managers automatically resolve, download, and install these required dependencies.
- Repository (Repo): A remote or local server hosting collections of verified packages.
- Package Ecosystems:
- Debian / Ubuntu:
.debpackages managed byaptanddpkg. - RHEL / Rocky / AlmaLinux / Fedora:
.rpmpackages managed bydnf(and historicallyyum).
- Debian / Ubuntu:
12.2 Debian & Ubuntu Family (APT & DPKG)
Section titled “12.2 Debian & Ubuntu Family (APT & DPKG)”The Debian family uses .deb package archives.
High-Level Manager: apt
Section titled “High-Level Manager: apt”apt (Advanced Package Tool) handles remote repository downloads and automated dependency resolution:
# Update local package metadata cache (Always run before installing!)sudo apt update
# Upgrade all installed packages to their latest versionssudo apt upgrade -y
# Install a packagesudo apt install nginx -y
# Remove a package (preserves configuration files)sudo apt remove nginx
# Purge a package (removes package AND all configuration files)sudo apt purge nginx
# Search repository packagesapt search "web server"
# Clean local package cache (.deb archives in /var/cache/apt/archives)sudo apt cleanLow-Level Manager: dpkg
Section titled “Low-Level Manager: dpkg”dpkg installs .deb files directly from disk without resolving remote dependencies:
# Install a local .deb packagesudo dpkg -i custom-app_1.0_amd64.deb
# If installation fails due to missing dependencies, resolve them with APT:sudo apt install -f
# List all installed packagesdpkg -l
# Search for installed files by package namedpkg -L nginxRepository Configuration
Section titled “Repository Configuration”Debian and Ubuntu define repositories in /etc/apt/sources.list and drop-in .list or .sources files inside /etc/apt/sources.list.d/.
12.3 RHEL & Fedora Family: The Evolution from YUM to DNF
Section titled “12.3 RHEL & Fedora Family: The Evolution from YUM to DNF”YUM (Yellowdog Updater, Modified) was RHEL’s primary package management utility up to RHEL 7. Starting with RHEL 8, YUM was replaced by DNF (Dandified YUM).
DNF offers superior performance, lower memory overhead, and modern features like transactional rollbacks, while retaining backward compatibility by aliasing yum to dnf.
YUM vs DNF Comparison
Section titled “YUM vs DNF Comparison”| Feature / Aspect | YUM (RHEL <= 7) | DNF (RHEL >= 8) |
||||
| Introduction Year | 2003 | 2013 |
| Language | Python 2 | C / C++ and Python 3 |
| Dependency Resolver | Custom heuristic algorithm (slower) | Libsolv-based (fast, SAT-solver algorithm) |
| Performance & Memory | High memory consumption, slower sync | Lightweight, fast metadata parsing |
| Parallel Downloads | Not supported | Supported natively |
| Modular Content | Not supported | Supported (Application Streams) |
| Transaction Rollback | Not supported | Supported (dnf history undo) |
| Transaction History | Basic | Extensive, auditable logs |
| Plugin Architecture | Limited Python plugins | Modular C/Python extensions |
| Current Status | Deprecated | Default, actively developed |
| CLI Compatibility | Native | yum redirects transparently to dnf |
12.4 Modern DNF Command Reference
Section titled “12.4 Modern DNF Command Reference”DNF commands are intuitive and match standard administration workflows:
# Install a packagesudo dnf install httpd -y
# Remove a package and its unused dependenciessudo dnf remove httpd -y
# Update a specific package or upgrade entire operating systemsudo dnf upgrade httpdsudo dnf upgrade -y
# List available or installed packagesdnf list availablednf list installed
# Search repositories by keyword or namednf search "web server"
# View detailed package metadatadnf info nginx
# Identify which package provides a specific file or binary (Vital for troubleshooting!)dnf provides /usr/bin/wgetTransaction History & Rollbacks
Section titled “Transaction History & Rollbacks”One of DNF’s greatest superpowers is its transactional integrity. Every package installation, upgrade, or removal is tracked in an auditable database that can be undone:
# View list of past transactions with IDs, actions, and datessudo dnf history
# View details of a specific transactionsudo dnf history info 12
# Roll back / undo a problematic installation or updatesudo dnf history undo 12Modular Application Streams (dnf module)
Section titled “Modular Application Streams (dnf module)”RHEL 8+ uses Application Streams to allow administrators to choose between multiple versions of software (e.g., Node.js 18 vs Node.js 20 or PostgreSQL 15 vs 16) without waiting for OS releases:
# List available streams for a modulednf module list nodejs
# Enable and install a specific version streamsudo dnf module enable nodejs:20 -ysudo dnf install nodejs -y
# Switch or reset module streamssudo dnf module reset nodejs12.5 Low-Level RPM & Repository Management
Section titled “12.5 Low-Level RPM & Repository Management”1. rpm (Red Hat Package Manager)
Section titled “1. rpm (Red Hat Package Manager)”Installs local .rpm packages and verifies disk file integrity against original package checksums:
# Install local .rpm package (-i install, -v verbose, -h hash progress bar)sudo rpm -ivh custom-agent-2.0.x86_64.rpm
# Query which package owns a specific filerpm -qf /etc/httpd/conf/httpd.conf
# Verify package integrity (detects altered binaries or permissions)rpm -V httpd2. Repository Configuration (/etc/yum.repos.d/)
Section titled “2. Repository Configuration (/etc/yum.repos.d/)”Both YUM and DNF store repository configurations in /etc/yum.repos.d/*.repo.
Enable or disable repositories dynamically using dnf config-manager:
# Install config-manager plugin if needed (dnf-plugins-core)sudo dnf install dnf-plugins-core -y
# Enable a repositorysudo dnf config-manager --set-enabled epel
# Disable a repositorysudo dnf config-manager --set-disabled epel-testing
# Add a new custom repository from URLsudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo12.6 Platform Selection & Best Practices
Section titled “12.6 Platform Selection & Best Practices”| Platform | Recommended Tool | Key Strengths | Legacy Fallback |
|||||
| RHEL 7 / CentOS 7 | yum | Stable, field-proven | Native |
| RHEL 8, 9 / Alma / Rocky | dnf | Libsolv, modular streams, rollbacks | yum alias |
| Ubuntu / Debian | apt | Broad package availability, PPA support | dpkg |
Package Hygiene Best Practices
Section titled “Package Hygiene Best Practices”- Audit Repositories: Periodically inspect
/etc/apt/sources.list.d/and/etc/yum.repos.d/to remove unverified third-party repositories. - Clean Caches Regularly: Run
dnf clean allorapt cleanon systems with small disk footprints to reclaim gigabytes of cached packages. - Use Transactional Rollbacks: Leverage
dnf history undowhenever an update breaks an application rather than manually attempting to reinstall old packages.