What is a Package Manager?#
A package manager handles installing, updating, and removing software on your system. Instead of downloading binaries manually, you tell the package manager what you want and it:
- Finds the software in a repository (a trusted server hosting packages)
- Resolves dependencies (other packages the software needs)
- Downloads and installs everything in the right place
- Tracks what’s installed so it can update or remove it later
Every major Linux distribution ships with a package manager. The two most common are:
| Distribution Family | Package Manager | Package Format |
|---|---|---|
| Debian, Ubuntu, Mint | apt | .deb |
| RHEL, Fedora, Rocky, AlmaLinux | dnf | .rpm |
Repositories#
Repositories are remote servers that host packages. Your system is configured to trust specific repos and pull software from them.
Viewing configured repositories#
| Action | apt (Debian/Ubuntu) | dnf (RHEL/Fedora) |
|---|---|---|
| List repos | cat /etc/apt/sources.list | dnf repolist |
| List all (including disabled) | grep -r ^deb /etc/apt/sources.list.d/ | dnf repolist --all |
Adding a repository#
apt:
# Add a PPA (Ubuntu)
sudo add-apt-repository ppa:example/repo
# Add a third-party repo manually
echo "deb https://packages.example.com/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/example.list
sudo apt updatednf:
# Add a repo from a URL
sudo dnf config-manager --add-repo https://packages.example.com/fedora/example.repo
# Or install a repo package
sudo dnf install https://packages.example.com/example-release.rpmCore Operations#
Update package lists / metadata#
Before installing software, sync your local package database with the repos:
| Action | apt | dnf |
|---|---|---|
| Refresh package metadata | sudo apt update | sudo dnf check-update |
apt requires this as a separate step. dnf refreshes metadata automatically when needed but you can check manually.
Install a package#
| Action | apt | dnf |
|---|---|---|
| Install | sudo apt install nginx | sudo dnf install nginx |
| Install without prompts | sudo apt install -y nginx | sudo dnf install -y nginx |
| Install multiple packages | sudo apt install nginx curl git | sudo dnf install nginx curl git |
Remove a package#
| Action | apt | dnf |
|---|---|---|
| Remove (keep config) | sudo apt remove nginx | sudo dnf remove nginx |
| Remove + config files | sudo apt purge nginx | sudo dnf remove nginx (removes configs by default) |
| Remove unused dependencies | sudo apt autoremove | sudo dnf autoremove |
Upgrade installed packages#
| Action | apt | dnf |
|---|---|---|
| Upgrade all packages | sudo apt upgrade | sudo dnf upgrade |
| Upgrade with dependency changes | sudo apt full-upgrade | sudo dnf distro-sync |
Searching for Packages#
| Action | apt | dnf |
|---|---|---|
| Search by name/description | apt search nginx | dnf search nginx |
| Show package details | apt show nginx | dnf info nginx |
| Find which package provides a file | apt-file search /usr/bin/htop | dnf provides /usr/bin/htop |
| List installed packages | apt list --installed | dnf list installed |
Working with Package Files#
Sometimes you need to install a package file directly (downloaded from a website, for example):
| Action | apt | dnf |
|---|---|---|
| Install a local package file | sudo apt install ./package.deb | sudo dnf install ./package.rpm |
Both will resolve dependencies from your configured repos automatically.
Package Information and History#
What files does a package install?#
| Action | apt | dnf |
|---|---|---|
| List files in installed package | dpkg -L nginx | rpm -ql nginx |
| List files in a package file | dpkg -c package.deb | rpm -qlp package.rpm |
Which package owns a file?#
| Action | apt | dnf |
|---|---|---|
| Find owning package | dpkg -S /usr/bin/curl | rpm -qf /usr/bin/curl |
Transaction history#
dnf keeps a log of everything it’s done:
# View history
dnf history
# Undo the last transaction
sudo dnf history undo lastapt logs to /var/log/apt/history.log:
cat /var/log/apt/history.logHolding / Locking Package Versions#
Prevent a package from being upgraded:
apt:
# Hold a package
sudo apt-mark hold nginx
# Release the hold
sudo apt-mark unhold nginx
# View held packages
apt-mark showholddnf:
# Install the versionlock plugin if needed
sudo dnf install dnf-plugins-core
# Lock a package
sudo dnf versionlock add nginx
# Remove the lock
sudo dnf versionlock delete nginx
# List locks
dnf versionlock listCleaning Up#
| Action | apt | dnf |
|---|---|---|
| Remove cached package files | sudo apt clean | sudo dnf clean all |
| Remove only outdated caches | sudo apt autoclean | sudo dnf clean packages |
| Remove orphaned dependencies | sudo apt autoremove | sudo dnf autoremove |
Understanding Dependencies#
When you install a package, the package manager pulls in everything it needs:
# See what a package depends on
apt depends nginx
dnf deplist nginx
# See what depends on a package (reverse dependencies)
apt rdepends nginx
dnf repoquery --whatrequires nginxDependency conflicts are rare with standard repos but can happen when mixing third-party repositories. If you hit a conflict:
- Read the error — it usually names the conflicting packages
- Check if you have third-party repos that overlap with official ones
- Prefer the official repo version unless you have a specific reason not to
Key Differences Between apt and dnf#
| Aspect | apt | dnf |
|---|---|---|
| Metadata refresh | Manual (apt update) | Automatic |
| Transaction rollback | Not built-in | dnf history undo |
| Config file handling on remove | Kept unless purge | Removed with package |
| Module/stream concept | No | Yes (dnf modules for versioned software) |
| Default in | Debian, Ubuntu | Fedora, RHEL 8+, Rocky, Alma |
Other Package Managers#
You’ll encounter these on other distributions:
| Manager | Distribution | Notes |
|---|---|---|
zypper | openSUSE, SLES | Similar to dnf in capability |
pacman | Arch, Manjaro | Rolling release, very fast |
apk | Alpine | Minimal, used heavily in containers |
snap | Ubuntu (cross-distro) | Sandboxed, auto-updating |
flatpak | Cross-distro | Sandboxed desktop applications |
The concepts are the same across all of them — repos, dependencies, install, remove, update. Only the commands differ.
Best Practices#
- Run
apt updatebefore installing anything on Debian/Ubuntu — stale metadata causes “package not found” errors - Use
autoremoveperiodically to clean up orphaned dependencies - Prefer official repos over third-party ones — they’re tested against your distribution
- Don’t mix packages from different distribution versions — a package built for Ubuntu 24.04 may break on 22.04
- Use version locks when you need stability on a specific package version (databases, runtimes)
- Check
dnf historyor/var/log/apt/history.logwhen troubleshooting — knowing what changed helps isolate problems - Keep your system updated —
sudo apt upgradeorsudo dnf upgraderegularly patches security vulnerabilities

