In the world of Linux system administration, package management is a foundational skill. Packages—precompiled software bundles containing binaries, configuration files, and metadata—are the building blocks of a Linux system. Efficiently managing these packages ensures system stability, security, and consistency. Two dominant package management ecosystems power most Linux distributions: RPM (used by Red Hat-based systems) and APT (used by Debian-based systems). This guide dives deep into RPM and APT, covering their core concepts, command-line tools, common workflows, and best practices. Whether you’re maintaining a fleet of RHEL servers or managing Ubuntu workstations, this article will equip you with the knowledge to handle packages like a pro.
Table of Contents
- Understanding Package Management
- RPM Package Management
- APT Package Management
- RPM vs. APT: A Comparison
- Best Practices for Package Management
- Conclusion
- References
Understanding Package Management
Before diving into RPM and APT, let’s define key terms:
- Package: A compressed archive containing software binaries, libraries, configuration files, and metadata (version, dependencies, maintainer). Examples:
.rpm(RPM) and.deb(APT). - Dependency: A requirement for a package to function (e.g., a library or another package). Package managers resolve dependencies automatically.
- Repository: A remote server hosting packages and metadata, enabling centralized distribution and updates.
- Package Manager: A tool to install, update, remove, and verify packages, handling dependencies and repositories.
RPM Package Management
RPM Core Concepts
RPM (Red Hat Package Manager) is used by Red Hat-based distributions: RHEL, CentOS, Fedora, Rocky Linux, and SUSE. Key components:
.rpmFiles: Binary package format containing software and metadata.- RPM Database: A centralized database (
/var/lib/rpm/) tracking installed packages, versions, and files. - Repositories: Remote or local storage for packages (e.g., Fedora’s official repos, EPEL for extra packages).
- YUM/DNF: High-level tools that simplify dependency resolution and repository management (we’ll cover these later).
Low-Level Tool: rpm
The rpm command is the low-level tool for interacting directly with .rpm packages. It lacks built-in repository support, so use it for local packages or debugging.
Common rpm Commands
| Task | Command Example | Description |
|---|---|---|
| Query installed package | rpm -q <package> | Check if a package is installed (e.g., rpm -q httpd). |
| List all installed packages | rpm -qa | List every package on the system (filter with grep: `rpm -qa |
| Show package details | rpm -qi <package> | Display metadata (version, dependencies, description). |
Install a local .rpm | sudo rpm -i <package.rpm> | Install a local package (e.g., sudo rpm -i google-chrome-stable.rpm). |
| Upgrade a package | sudo rpm -U <package.rpm> | Upgrade to a newer version (installs if not present). |
| Remove a package | sudo rpm -e <package> | Uninstall a package (e.g., sudo rpm -e httpd). |
| Verify package integrity | rpm -V <package> | Check if files from a package have been modified (e.g., rpm -V httpd). |
| List files in a package | rpm -ql <package> | Show all files installed by a package (e.g., rpm -ql httpd). |
| Find which package owns a file | rpm -qf /path/to/file | Identify the package providing a file (e.g., rpm -qf /usr/bin/nginx). |
Notes:
- Use
--forceto overwrite existing files (e.g.,rpm -i --force oldpackage.rpm). - Use
--nodepsto bypass dependency checks (Caution: Breaks dependencies!).
High-Level Tools: YUM and DNF
Raw rpm is limited—YUM (Yellowdog Updater Modified) and DNF (Dandified YUM) handle repositories, dependency resolution, and updates more efficiently. DNF is the modern replacement for YUM (used in Fedora, RHEL 8+).
Common YUM/DNF Commands
| Task | YUM Command | DNF Command |
|---|---|---|
| Update package indexes | sudo yum check-update | sudo dnf check-update |
| Upgrade all packages | sudo yum upgrade | sudo dnf upgrade |
| Install a package | sudo yum install <package> | sudo dnf install <package> |
| Remove a package | sudo yum remove <package> | sudo dnf remove <package> |
| Search for a package | yum search <keyword> | dnf search <keyword> |
| Show package details | yum info <package> | dnf info <package> |
| List enabled repos | yum repolist | dnf repolist |
| Clean cached packages | sudo yum clean all | sudo dnf clean all |
Example Workflow: Install Apache on Fedora
# Update package indexes
sudo dnf check-update
# Install Apache (httpd)
sudo dnf install httpd
# Verify installation
rpm -qi httpd
# Start and enable the service (not RPM-specific)
sudo systemctl start httpd && sudo systemctl enable httpd
Common RPM Workflows
1. Resolving Missing Dependencies
If rpm -i fails due to missing dependencies, use DNF to fetch them:
# DNF automatically resolves dependencies from repos
sudo dnf install ./local-package.rpm
2. Finding Packages for a File
To find which package provides /usr/bin/ssh:
rpm -qf /usr/bin/ssh # Output: openssh-clients-8.0p1-14.el8.x86_64
3. Verifying Package Integrity
Check if httpd files were modified (e.g., by a misconfiguration or attack):
rpm -V httpd
# Output (if modified): S.5....T. c /etc/httpd/conf/httpd.conf
APT Package Management
APT Core Concepts
APT (Advanced Package Tool) is used by Debian-based distributions: Debian, Ubuntu, Mint, and Kali Linux. Key components:
.debFiles: Binary package format (lower-level than.rpm).dpkg: Low-level tool to install/remove.debfiles (no repo support).- APT: High-level tool handling repositories, dependencies, and updates.
- Repositories: Defined in
/etc/apt/sources.listor/etc/apt/sources.list.d/.
Low-Level Tool: dpkg
dpkg is APT’s low-level counterpart, interacting directly with .deb files. It lacks dependency resolution, so use it for local .deb installation.
Common dpkg Commands
| Task | Command Example | Description |
|---|---|---|
Install a local .deb | sudo dpkg -i <package.deb> | Install a .deb file (e.g., sudo dpkg -i google-chrome-stable.deb). |
| Remove a package | sudo dpkg -r <package> | Remove a package (keeps config files). |
| Purge a package | sudo dpkg -P <package> | Remove a package and its config files. |
| List installed packages | dpkg -l | List all installed packages (filter with grep: `dpkg -l |
| List files in a package | dpkg -L <package> | Show files installed by a package (e.g., dpkg -L nginx). |
| Find which package owns a file | dpkg -S /path/to/file | Identify the package providing a file (e.g., dpkg -S /usr/bin/ssh). |
High-Level Tool: apt
apt is APT’s user-friendly front-end, combining apt-get (old tool) and apt-cache (search tool) into a single interface. It handles repositories and dependencies seamlessly.
Common apt Commands
| Task | Command Example | Description |
|---|---|---|
| Update package indexes | sudo apt update | Fetch latest repo metadata (run before upgrades). |
| Upgrade all packages | sudo apt upgrade | Upgrade installed packages (no new packages). |
| Full upgrade (add/remove packages) | sudo apt full-upgrade | Upgrade and add/remove packages to resolve dependencies. |
| Install a package | sudo apt install <package> | Install a package and dependencies (e.g., sudo apt install nginx). |
| Remove a package | sudo apt remove <package> | Remove a package (keeps config files). |
| Purge a package | sudo apt purge <package> | Remove a package and config files. |
| Autoremove unused packages | sudo apt autoremove | Remove orphaned dependencies (no longer needed by installed packages). |
| Search for a package | apt search <keyword> | Search repos for packages matching a keyword (e.g., apt search text-editor). |
| Show package details | apt show <package> | Display metadata (version, dependencies, description). |
Common APT Workflows
1. Installing a Local .deb with Dependencies
If dpkg -i fails due to missing dependencies:
# Fix missing dependencies for a local .deb
sudo dpkg -i ./local-package.deb # Fails due to dependencies
sudo apt --fix-broken install # APT resolves and installs dependencies
2. Cleaning Up Unused Packages
Free disk space by removing orphaned dependencies and cached packages:
sudo apt autoremove # Remove unused dependencies
sudo apt clean # Clear cached .deb files (in /var/cache/apt/archives/)
3. Holding a Package Version
Prevent a package from being updated (e.g., to avoid breaking changes):
sudo apt-mark hold nginx # Hold nginx at current version
sudo apt-mark unhold nginx # Allow updates again
RPM vs. APT: A Comparison
| Feature | RPM (Red Hat-based) | APT (Debian-based) |
|---|---|---|
| Package Format | .rpm | .deb |
| Low-Level Tool | rpm | dpkg |
| High-Level Tool | YUM/DNF | APT (apt, apt-get) |
| Repo Configuration | /etc/yum.repos.d/ (YUM/DNF) | /etc/apt/sources.list (APT) |
| Dependency Resolution | YUM/DNF (automatic) | APT (automatic) |
| Update Command | dnf upgrade | apt upgrade |
| Remove Orphans | dnf autoremove | apt autoremove |
| Search Packages | dnf search <keyword> | apt search <keyword> |
Best Practices for Package Management
1. Use Official Repositories
Third-party repos (e.g., EPEL for RPM, PPAs for APT) can introduce conflicts. Prioritize official repos for stability.
2. Regularly Update Packages
Security patches are critical. Schedule updates (e.g., with cron):
# Example: Weekly DNF update on Sunday at 3 AM
0 3 * * 0 sudo dnf upgrade -y
3. Avoid --nodeps or Forcing Installs
Bypassing dependencies (rpm --nodeps, dpkg --force-depends) breaks system consistency. Only use as a last resort.
4. Clean Up Cached Packages
Free disk space by clearing cached packages:
# RPM (DNF)
sudo dnf clean all
# APT
sudo apt clean
5. Verify Package Integrity
Check for tampering with rpm -V (RPM) or debsums (APT):
# APT: Install debsums first
sudo apt install debsums
sudo debsums nginx # Verify nginx files
6. Document Changes
Track installed packages with dnf list installed > packages.txt (RPM) or dpkg -l > packages.txt (APT) for reproducibility.
Conclusion
RPM and APT are powerful tools for managing Linux packages, each tailored to their respective ecosystems. By mastering low-level tools like rpm and dpkg, and high-level tools like DNF/YUM and APT, sysadmins can ensure systems remain secure, up-to-date, and consistent. Remember to prioritize official repositories, avoid dependency bypasses, and document changes—these practices will save time and prevent headaches in the long run.