apt vs yum vs dnf hand on laptop
apt vs yum vs dnf hand on laptop

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 or apt-get
  • The Red Hat Family (uses yum or dnf):
    • 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.

TaskDebian/Ubuntu (apt)Modern Red Hat (dnf)Legacy Red Hat (yum)
Install a Packagesudo apt install nginxsudo dnf install nginxsudo yum install nginx
Remove a Packagesudo apt remove nginxsudo dnf remove nginxsudo yum remove nginx
Update Package Listssudo apt updatesudo dnf check-updatesudo yum check-update
Upgrade Packagessudo apt upgradesudo dnf upgradesudo yum update
Search for a Packageapt search python3dnf search python3yum search python3
Show Package Infoapt show nginxdnf info nginxyum info nginx
Clean Package Cachesudo apt cleansudo dnf clean allsudo yum clean all
Autoremove Old Packagessudo apt autoremovesudo dnf autoremovesudo 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 for apt.
  • .rpm packages are for dnf/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:

  1. Check your OS: cat /etc/os-release
  2. Know your family: Debian or Red Hat?
  3. 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 installremove, 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.

macOS Security for Admins

macOS Security for Admins: The 2025 Enterprise Management & Hardening Guide Introduction: The Modern Mac…

Read More

Leave a Comment

Your email address will not be published. Required fields are marked *