Master Linux Package Management: apt vs dnf Commands Explained
This guide walks you through searching, installing, updating, and removing software on Linux using the apt and dnf package managers, covering command syntax, regex searches, group installations, and how each tool handles caches and configuration files.
Searching for Packages
To locate a package, use dnf search <keyword> or apt search <keyword>. Both commands return matching package names and short descriptions. Regular expressions can narrow results, e.g., apt search ^zsh.
sudo dnf search zsh sudo apt search zshFinding Which Package Provides a Command
When you know a command but not its package, dnf provides <command> or apt-file search <path> reveal the owning package.
sudo dnf provides pgrep sudo apt-file search /usr/bin/pgrepInstalling Packages
Installation syntax is identical for both managers:
sudo apt install zsh sudo dnf install zshRPM‑based distributions also support group installations, which bundle related applications. List available groups with dnf group list -v and install a group using dnf group install <group-name>. The shortcut @design-suite can be used to refer to a group.
sudo dnf group list -v sudo dnf group install design-suiteUpdating Packages
Both tools can upgrade installed software. apt upgrade updates packages based on a cached index, while dnf upgrade (or dnf update) refreshes metadata on each run and then upgrades.
sudo apt upgrade sudo dnf upgradeRemoving Packages
To uninstall a package, use the remove subcommand. Apt keeps user configuration files by default; add purge to delete them as well. Neither manager removes files in the user’s home directory automatically.
sudo dnf remove zsh sudo apt remove zsh sudo apt purge zshKey Takeaways
Whether your distribution uses apt (Debian/Ubuntu) or dnf (Fedora/RHEL), the core operations—search, install, update, and remove—are very similar, making it easy to switch between them. Both provide advanced features such as repository management, but the basic commands covered here handle the majority of everyday package tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
