
apt vs yum vs dnf: The Linux Package Manager Cheat Sheet for 2025
Your Distribution’s App Store is a Command Line. Let’s Master It.
If you jump between Ubuntu and Red Hat servers, that moment of panic is real. You need to install a package. Was it apt-get install
or yum install
? Or is it dnf
now?
You’re not forgetting things. You’re just dealing with the two major tribes of Linux: the Debian family and the Red Hat family. And each has its own package management philosophy.
This isn’t about which one is “better.” It’s about giving you a crystal-clear cheat sheet so you can work effectively in either environment without missing a beat.
Let’s break down the players and their commands.
The Teams: Know Your Distribution Family
First, know which camp you’re in. This decides your tool.
- The Debian Family (uses
apt
):- Ubuntu: The most popular desktop and cloud distro.
- Debian: The rock-solid, stable granddaddy.
- Linux Mint, Pop!_OS: Ubuntu derivatives.
- Their Command:
apt
orapt-get
- The Red Hat Family (uses
yum
ordnf
):- Red Hat Enterprise Linux (RHEL): The enterprise king.
- Fedora: The cutting-edge community project.
- CentOS: (Historically) The free RHEL clone. Now: CentOS Stream is a rolling release.
- Rocky Linux & AlmaLinux: The new free RHEL clones, replacing CentOS.
- Their Command: On RHEL 7/CentOS 7 and older:
yum
. On RHEL 8+/Rocky Linux/AlmaLinux/Fedora:dnf
.
The Key Takeaway: dnf
is the modern replacement for yum
. It’s better, faster, and has smarter dependency resolution. If you’re on a modern Red Hat family distro, you use dnf
. The commands are almost identical to yum
.
The Cheat Sheet: Command vs. Command
This is the table you’ll come back to. These commands do the exact same thing on their respective distributions.
Task | Debian/Ubuntu (apt) | Modern Red Hat (dnf) | Legacy Red Hat (yum) |
---|---|---|---|
Install a Package | sudo apt install nginx | sudo dnf install nginx | sudo yum install nginx |
Remove a Package | sudo apt remove nginx | sudo dnf remove nginx | sudo yum remove nginx |
Update Package Lists | sudo apt update | sudo dnf check-update | sudo yum check-update |
Upgrade Packages | sudo apt upgrade | sudo dnf upgrade | sudo yum update |
Search for a Package | apt search python3 | dnf search python3 | yum search python3 |
Show Package Info | apt show nginx | dnf info nginx | yum info nginx |
Clean Package Cache | sudo apt clean | sudo dnf clean all | sudo yum clean all |
Autoremove Old Packages | sudo apt autoremove | sudo dnf autoremove | sudo yum autoremove |
See the pattern? The structure is identical: [manager] [command] [package]
.
The “Apt” Advantage: A Note on apt
vs apt-get
You’ll see both apt
and apt-get
on Ubuntu systems. What’s the difference?
apt-get
: The older, stable, low-level command. It’s bulletproof and perfect for scripts.apt
: The newer, user-friendly command designed for humans. It provides prettier output, a progress bar, and is easier to use.
For 99% of what you do interactively, just use apt
. It’s simpler and more intuitive.
bash
# Do this: sudo apt update && sudo apt upgrade # Not this: sudo apt-get update && sudo apt-get upgrade
(They both work, but the first is cleaner).
The “DNF” Advantage: Why It Replaced Yum
If yum
worked fine, why did they replace it? dnf
isn’t just a rename; it’s a genuine upgrade.
- Better Dependency Resolution: It’s much smarter at figuring out what to install and remove, leading to fewer broken systems.
- Better Performance: It’s written in Python 3 and is generally faster, especially with metadata.
- Strict API: Makes it more stable for developers and scripts long-term.
The good news? The commands are so similar that if you know yum
, you already know dnf
. It’s a drop-in replacement for interactive use.
The Bottom Line: It’s About the Repos, Not the Tool
The real difference between apt
and dnf
isn’t the syntax. It’s the software repositories they connect to.
.deb
packages are forapt
..rpm
packages are fordnf
/yum
.
You can’t use apt
to install an .rpm
file, and vice-versa. The package managers are the keys to their own distinct kingdoms.
Your goal isn’t to memorize everything. It’s to know which kingdom you’re in and have the cheat sheet handy.
So, the next time you SSH into a server:
- Check your OS:
cat /etc/os-release
- Know your family: Debian or Red Hat?
- Use the right cheat sheet. That’s it. You’re golden.
Managing a hybrid environment? Our guide on [ Linux server provisioning for DevOps] covers how to use tools like Ansible to handle these differences automatically.
FAQ Section
Q: Should I use apt or apt-get on Ubuntu?
A: For interactive use in the terminal, use apt
. It provides a more user-friendly experience with progress bars and clearer output. For writing shell scripts, many still prefer apt-get
because its output is more stable and consistent, making it better for parsing by other programs.
Q: Is DNF backwards compatible with YUM?
A: For most everyday commands, yes. dnf
is designed to be a drop-in replacement for yum
, so commands like install
, remove
, and update
work identically. However, for more advanced scripting or plugins, there might be differences, so it’s important to test scripts after migrating from a yum
-based system to a dnf
-based one.
Q: Can I install .deb packages on Red Hat or .rpm packages on Ubuntu?
A: It’s possible but not recommended and often leads to dependency nightmares. You can use conversion tools like alien
or low-level tools like dpkg
on an RPM system, but it’s fragile. The correct method is to find the package in the native repository for your distribution or use a third-party repo that provides the correct package format.
Q: Which Linux distribution is better for beginners, Ubuntu or Fedora?
A: For absolute beginners, Ubuntu tends to be the most recommended. It has a massive community, extensive documentation, and a focus on ease of use. Fedora is also excellent but is often seen as more cutting-edge, which can sometimes introduce instability. Both use package managers (apt
and dnf
) that are equally powerful once you understand the basic syntax differences.
How to Create a Bootable macOS USB Installer (2025 Guide: Sonoma & Ventura)
How to Create a Bootable macOS USB Installer (2025 Guide: Sonoma & Ventura) Your Mac…
macOS LaunchAgents vs LaunchDaemons: The Admin’s Guide to Startup Persistence
macOS LaunchAgents vs LaunchDaemons: The Admin’s Guide to Startup Persistence Forget “Startup Items.” This is…
How to Use journalctl: The Linux Log Guru’s Cheat Sheet for 2025
How to Use journalctl: The Linux Log Guru’s Cheat Sheet for 2025 Stop Grepping in…
How to Fix High CPU or Memory Usage in Windows 10/11: The Sysadmin’s Guide
How to Fix High CPU or Memory Usage in Windows 10/11: The Sysadmin’s Guide Introduction:…
macOS Security for Admins
macOS Security for Admins: The 2025 Enterprise Management & Hardening Guide Introduction: The Modern Mac…
What is Operating System Kernel? The Heart of Every OS Explained
What is Operating System Kernel ? The Heart of Every OS Explained Introduction: The Silent…