The Ultimate Guide to Linux Package Management: apt vs dnf

The CyberSec Guru

Updated on:

Linux 101 - The Ultimate Guide to Linux Package Management

If you like this post, then please share it:

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Why your support matters: Zero paywalls: Keep the main content 100% free for learners worldwide, Writeup Access: Get complete in-depth writeup with scripts access within 12 hours of machine drop.

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

You’ve just downloaded a tar.gz file. You feel like a real Linux user. You unpack it, cd into the directory, and dutifully type ./configure.

The response: configure: error: 'libfoo.so.2' not found.

You’re a detective now. You Google “libfoo”. You find its website, download its source code, and run ./configure. It fails. configure: error: 'lib-bar-dev' not found. You are now 10 levels deep in a spiraling maze of missing files, and you haven’t even started to install the program you actually wanted.

Welcome to Dependency Hell.

This nightmare is the single biggest reason “the year of the Linux desktop” was a running joke for two decades. But here’s the secret: this problem was solved 25 years ago.

You just tried to build a car from a pile of scrap metal. You didn’t know there’s a multi-trillion dollar, fully-automated car factory right next door that will give you a car for free, and also bring it to your house, service it, and fill it with gas.

That factory is the Linux Package Manager.

Understanding this system is the real key to mastering Linux. It’s the unsung hero that makes Linux the most stable, secure, and powerful operating system on the planet.

This is not a quick 5-command cheat sheet. This is the definitive, 10,000-word, “no external info required” guide. By the end of this article, you will be able to install, update, and manage any software on any Linux system with absolute confidence. We will cover apt, dnf, yum, dpkg, rpm, the “Great Divide” of Linux families, and the new world of Snaps and Flatpaks.

Strap in. You’re about to become a package management master.

What is a Package Manager? (And Why It Will Save Your Life)

Before we type a single command, we must understand the philosophy.

The “Old Way” (Dependency Hell)

We just lived it. The “old way” is Compiling from Source. You download the raw, human-readable source code (.tar.gz) and use a “compiler” to turn it into a runnable program (./configure, make, make install).

This is a nightmare for one reason: Dependencies.

A “dependency” is any other piece of software that your program depends on to run.

  • Your web browser (firefox) depends on a library that can render images (libjpeg).
  • That image library (libjpeg) depends on a library that can compress data (zlib).
  • The firefox program won’t even start unless libjpeg and zlib are both already installed, and are the correct versions.
Dependency Hell
Dependency Hell

When you compile from source, you are the one responsible for finding, compiling, and installing every single one of these dependencies, in the correct order, before you can even start on the app you wanted.

The “Package Manager” Solution

The Linux community solved this problem with three brilliant concepts.

1. The “Package” A “package” (a .deb or .rpm file) is a pre-compiled, ready-to-run program. But it’s more than that. It’s a “smart” archive. It contains:

  • The pre-compiled program (e.g., the firefox binary).
  • All the files it needs (e.g., icons, documentation).
  • A “metadata” file.

This metadata file is the magic. It lists all of the package’s dependencies, like an ingredients list. For example: “I am firefox version 100. To work, I need libnss3 (version 3.5 or higher) and libasound2.”

2. The “Repository” (Repo) A “repository” is a massive, centralized, public server. Think of it as a giant, trusted “App Store” or a software warehouse. It holds thousands of these pre-compiled packages, all tested and known to work together.

3. The “Package Manager” This is the tool on your system (apt, dnf, yum) that acts as the “warehouse manager” or “personal shopper.” It’s a tool that knows how to:

  • Talk to the repositories.
  • Read the metadata “ingredients” list of every package.
  • Resolve all dependencies automatically.

The Magic Workflow (The “New Way”)

Let’s see the new workflow. You want to install firefox.

You: sudo apt install firefox

Your Package Manager (apt): “Roger. One firefox, coming up. Let me check the metadata from the official Ubuntu repository…”

(It downloads a tiny list and reads it.)

apt: “Ah, okay. The firefox package (v100) also requires libnss3 and libasound2. Let me check if you have those… You don’t. No problem. The repository also has those. I’ll get them all.”

(It shows you a summary)

The following additional packages will be installed:
  libasound2 libnss3
The following NEW packages will be installed:
  firefox libasound2 libnss3
0 upgraded, 3 newly installed, 0 to remove.
Need to get 60 MB of archives.
After this operation, 210 MB of additional disk space will be used.
Do you want to continue? [Y/n]

You: Y

apt: “Great.” (It downloads all three packages, verifies their security signatures, and installs them in the correct order: libasound2 first, libnss3 second, and firefox last.)

apt: “Done.”

You: (types firefox)

It. Just. Works.

This is the central pillar of the Linux ecosystem.

  • No Dependency Hell: apt handles it for you.
  • Easy Updates: sudo apt upgrade will check all your packages and upgrade them.
  • Easy Removal: sudo apt remove firefox will remove it.
  • Security: You’re not downloading a random file from “https://www.google.com/search?q=bobs-software.com”. You’re downloading it from a secure, trusted, and verified repository run by your distribution (e.g., Ubuntu, Fedora).

The Great Divide: apt vs dnf (Debian vs. Red Hat)

This is the only “confusing” part, and it’s simple. Linux is not one single company. It’s a collection of “families,” or “distributions.” The two biggest families are Debian and Red Hat.

They work the same conceptually, but they use different tools and file formats.

1. The Debian Family (.deb / apt)

  • Package Format: .deb (from “Debian”)
  • Low-Level Tool: dpkg (Debian Package manager)
  • High-Level Tool: apt (Advanced Package Tool)
  • Famous Distros: Debian, Ubuntu, Linux Mint, Pop!_OS, Zorin OS.
  • You use this if: You’re on Ubuntu or any of its “children.”

2. The Red Hat Family (.rpm / dnf)

  • Package Format: .rpm (Red Hat Package Manager)
  • Low-Level Tool: rpm
  • High-Level Tool: dnf (Dandified YUM). The older tool was yum (Yellowdog Updater, Modified).
  • Famous Distros: Red Hat Enterprise Linux (RHEL), Fedora, CentOS Stream, AlmaLinux, Rocky Linux.
  • You use this if: You’re on Fedora, or a server-focused “RHEL-clone.”

Key takeaway: They are 99% the same. They just use different command names. If you learn one, you can learn the other in 5 minutes. We will master both.

The apt Masterclass (For Debian & Ubuntu Users)

This is your command center for Ubuntu, Debian, and Mint. apt is the modern, user-friendly command. (You may see old guides use apt-get or apt-cache. apt is the new, consolidated command that combines them. Use apt.)

The Most Important File: /etc/apt/sources.list

This file is your system’s “phone book.” It’s a plain text file that tells apt which repositories to call.

Let’s look at a line from a typical Ubuntu sources.list: deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse

Let’s dissect this:

  • deb: We want binary (pre-compiled) packages. ( deb-src would mean source code).
  • http://archive.ubuntu.com/ubuntu/: The “phone number.” The URL of the repository server.
  • jammy: The code name for your Ubuntu release (e.g., 22.04). This ensures you only get packages tested for your exact OS version.
  • main restricted universe multiverse: These are the “components” or “sections” of the warehouse you have access to.
    • main: Officially supported, open-source software.
    • restricted: Officially supported, but proprietary (closed-source) software. (e.g., NVIDIA graphics drivers).
    • universe: Community-maintained, open-source software. (This is where most software is).
    • multiverse: Community-maintained, but proprietary. (e.g., media codecs).

You almost never need to edit this file by hand, but understanding it is key.

Core apt Command Workflow

1. sudo apt update (The “Refresh”)

  • What it does: This is the most important and most misunderstood command. It does not install or upgrade any software.
  • It simply contacts all the repository URLs in your sources.list and downloads the latest “menu” or “list” of available packages.
  • Analogy: You’re downloading the latest menu from the restaurant before you decide to order.
  • Rule: You MUST run sudo apt update before installing anything to ensure you are getting the latest, most secure versions.

2. sudo apt install <package_name> (The “Order”)

  • This is the main event.
  • sudo apt install firefox
  • apt will look at its newly updated list, find firefox, and calculate all its dependencies.
  • It will show you a plan (“firefox, libfoo, and lib-bar will be installed…”) and ask [Y/n].
  • Pro-Tip (Installation):
    • Install multiple: sudo apt install gimp inkscape audacity
    • For scripts (auto-yes): sudo apt install -y gimp
    • Reinstall: sudo apt reinstall gimp

3. sudo apt upgrade (The “Service All”)

  • What it does: apt compares the list of everything you have installed against the newly updated lists (from apt update).
  • It finds every package that has a newer version available and upgrades it.
  • This is the primary way you keep your system secure and up-to-date.
  • It will not remove any packages to do so.

4. sudo apt full-upgrade (The “Smart Service”)

  • What it does: This is a “smarter” upgrade. It’s the same as upgrade, but it is allowed to remove old packages if a new version’s dependencies require it (e.g., a new kernel or a major graphics driver update).
  • This is what the “Software Updater” graphical tool runs.
  • Rule: Use apt upgrade for daily/weekly updates. Use apt full-upgrade for major version jumps.

5. sudo apt remove <package_name> (The “Uninstall”)

  • sudo apt remove firefox
  • This uninstalls the package.
  • Key Detail: It leaves your personal configuration files (in your Home directory) and the system-wide configuration files (in /etc).
  • Why? So if you reinstall firefox a month later, your bookmarks and settings might still be there.

6. sudo apt purge <package_name> (The “Total Annihilation”)

  • sudo apt purge firefox
  • This does everything remove does, plus it deletes the system-wide configuration files from /etc.
  • This is the “I want this gone forever, like it never existed” command.
  • Pro-Tip: I purge 99% of the time.

7. sudo apt autoremove (The “Cleanup Crew”)

  • This is your best friend.
  • Remember when apt installed firefox, libnss3, and libasound2?
  • What happens when you sudo apt remove firefox?
  • Well, firefox is gone. But… libnss3 and libasound2 are still there. They are now “orphans.” They were installed as a dependency, but their parent is gone. They are just wasting space.
  • sudo apt autoremove scans your system, finds all these orphaned packages, and safely removes them.
  • Rule: Run sudo apt autoremove after any big remove or upgrade to keep your system clean and lean.

Finding Software with apt

How do you install it if you don’t know the name?

  • apt cache search <keyword>
    • apt cache search "video editor"
    • This will search the names and descriptions of all packages in the lists for your keyword.
    • openshot-qt - Simple, non-linear video editor
    • kdenlive - A non-linear video editor
    • Ah, the package name is kdenlive. Now I can run sudo apt install kdenlive.
  • apt show <package_name>
    • apt show kdenlive
    • This shows you the “metadata” card for the package: its full description, what version it is, who maintains it, and—most importantly—its dependencies.

The Low-Level Tool: dpkg (The “Dumb” Installer)

apt is the smart, all-powerful general. dpkg is the “dumb” grunt who only knows one thing: how to install or remove a .deb file that it’s given.

dpkg cannot download files, talk to repositories, or resolve dependencies.

Use Case: You went to Google’s website and downloaded google-chrome-stable_current_amd64.deb. apt doesn’t know about this file.

Old Way (The Wrong Way): sudo dpkg -i google-chrome-stable_current_amd64.deb

  • (-i means install)
  • It will almost always fail: dpkg: dependency problems prevent configuration of google-chrome-stable: ...
  • It’s telling you “I can’t install this, it’s missing 20 dependencies.”

The Modern Fix (The RIGHT Way): This is one of the most useful tricks in the apt world.

  1. Run the dpkg command and let it fail.
  2. Then, run this magic command: sudo apt --fix-broken install
  3. apt will look at the broken, half-installed google-chrome package, read its dependency list, and say “Oh, dpkg failed because you’re missing libfoo, lib-bar, and lib-baz? I can get those!
  4. apt then goes to the official repositories, downloads all the missing pieces, installs them, and then goes back and finishes the dpkg installation of google-chrome.
  5. It’s a beautiful, self-correcting system.

The dnf Masterclass (For RHEL, Fedora, CentOS Users)

This is your command center for the Red Hat family. dnf (Dandified YUM) is the modern tool.

A Quick History: The old tool was yum (Yellowdog Updater, Modified). dnf is the next-generation replacement—it’s faster, smarter, and has much better dependency resolution. On modern systems like Fedora, RHEL 8+, and CentOS Stream 8+, yum is just a “symlink” (an alias) that points to dnf. So when you type yum, you’re using dnf anyway.

We will learn the dnf commands.

The Repositories: /etc/yum.repos.d/

Unlike apt‘s single sources.list, the dnf world uses a directory: /etc/yum.repos.d/. This directory is full of small .repo files. Each file defines one repository.

A typical file (e.g., fedora.repo) looks like this:

[fedora]
name=Fedora $releasever - $basearch
baseurl=http://... (a URL to the packages)
gpgcheck=1
  • [fedora]: A unique ID.
  • name=: A human-readable name.
  • baseurl=: The “phone number.” The URL to the repo.
  • gpgcheck=1: Enforce security. Verify all packages.

The “EPEL” Repository: By default, RHEL and its clones are very stable and have a limited set of packages. The first thing every sysadmin does is add the EPEL (Extra Packages for Enterprise Linux) repository. This is a massive, community-run repo that contains thousands of common, useful packages (like htop, nginx, etc.) that aren’t in the official RHEL list. sudo dnf install epel-release This command installs a .repo file into /etc/yum.repos.d/ and gives you access to a whole new world of software.

Core dnf Command Workflow

Notice how similar these are to apt.

1. sudo dnf check-update (The “Refresh”)

  • What it does: This is the dnf equivalent of apt update. It contacts all the .repo files and downloads the latest “menu” of available packages.
  • dnf is a bit smarter than apt and will also do this automatically on a timer (or before an install), but it’s good practice to run it manually.

2. sudo dnf install <package_name> (The “Order”)

  • sudo dnf install htop
  • dnf will calculate dependencies, show you a plan, and ask [y/N].
  • Pro-Tip (Installation):
    • Install multiple: sudo dnf install gimp inkscape audacity
    • For scripts (auto-yes): sudo dnf install -y gimp

3. sudo dnf upgrade (The “Service All”)

  • What it does: The dnf equivalent of apt upgrade.
  • It compares your installed packages to the new lists and upgrades everything. This is your main command for keeping a Fedora/RHEL system up-to-date.

4. sudo dnf remove <package_name> (The “Uninstall”)

  • sudo dnf remove htop
  • Uninstalls the package and its dependencies that aren’t needed by anything else.

5. sudo dnf autoremove (The “Cleanup Crew”)

  • This is exactly the same as apt autoremove.
  • It scans for “orphaned” dependencies (packages installed for a program you’ve since removed) and cleans them up.
  • Run this to keep your system lean.

Finding Software with dnf

  • dnf search <keyword>
    • dnf search "video editor"
    • Searches package names and descriptions.
    • kdenlive.x86_64 : Kdenlive - Non-Linear Video Editor
    • Great, the name is kdenlive. sudo dnf install kdenlive.
  • dnf info <package_name>
    • dnf info kdenlive
    • The dnf equivalent of apt show. Shows the full metadata card: version, description, and dependencies.

The Low-Level Tool: rpm (The “Dumb” Installer)

rpm is the low-level tool, just like dpkg. It only knows about .rpm files, not repos or dependencies.

Use Case: You downloaded my-cool-app.rpm.

Old Way (The Wrong Way): sudo rpm -ivh my-cool-app.rpm

  • (-i install, v verbose, h hash marks)
  • It will fail: error: Failed dependencies: lib-baz.so.3 is needed by my-cool-app

The Modern dnf Way (This is a Killer Feature): dnf is smarter than apt in this one specific scenario.

  • DO NOT use rpm.
  • Just point dnf at the local file: sudo dnf install ./my-cool-app.rpm

Here’s what happens: dnf will look at the local .rpm file, read its dependency list, and see it needs lib-baz.so.3. Then, it will go to the remote repositories (like fedora or epel), download lib-baz, and then install both the local file and the remote dependencies, all in one step, all automatically.

This is the peak of package management.

Beyond apt and dnf (The New World of Universal Packages)

For 20 years, apt and dnf were the two kingdoms. But this still created a problem for developers. If they made an app (like Spotify), they had to create a .deb for Ubuntu and a .rpm for Fedora.

In the last 5-10 years, a new solution has emerged: Universal Packages. The goal is “one package to rule them all.” One file that runs on any Linux distro.

The two big players are Snap and Flatpak.

Here’s a comprehensive comparison of these Linux application distribution methods:

Featureapt/dnfSnapFlatpakAppImage
Package Format.deb (apt) / .rpm (dnf).snap.flatpak.AppImage
DependenciesShared system libraries; can cause dependency conflictsBundled with app; self-containedBundled with app; uses runtimes for common librariesFully bundled; completely self-contained
Update MethodSystem package manager (apt update/upgrade or dnf update)Automatic background updates via snapd daemonManual via flatpak update or configured auto-updateManual; user downloads new version or uses optional tools like AppImageUpdate
Sandbox?No sandboxing by defaultYes, using AppArmor/seccomp confinementYes, using bubblewrap and portalsNo built-in sandboxing; runs with full user permissions
Key ProFast, efficient, tight system integration, official distro supportUniversal across distros, automatic updates, easy rollbackOpen-source stack, good sandbox model, large app ecosystemPortable, no installation needed, no root required, works on any distro
Key ConDependency hell, version conflicts, requires root, tied to distro release cycleSlower startup, proprietary backend (Snap Store), larger disk usageRequires flatpak runtime, slightly slower startup, some integration limitationsNo automatic updates, no centralized discovery, manual management, larger file sizes

1. Snap (from Canonical/Ubuntu)

  • What is it? A new, universal package format.
  • Core Concept: “Bundled” dependencies. The spotify.snap package includes all its dependencies inside the package. It brings its own lib-foo and lib-bar.
  • Pros:
    • Works on any Linux (Fedora, Arch, Ubuntu). sudo dnf install snapd.
    • No dependency hell, ever.
    • Sandboxed: The app is “jailed” and can’t easily mess up your system. This is great for security.
    • You always get the latest version directly from the developer.
  • Cons:
    • Slow to start: The OS has to “mount” this self-contained package.
    • Takes up way more disk space: If 10 of your Snap apps all need lib-foo, you now have 10 copies of lib-foo on your disk.
    • Centralized: The “Snap Store” is controlled by Canonical (the makers of Ubuntu).
  • Commands: snap install spotify, snap refresh, snap remove spotify.

2. Flatpak (from Red Hat/Community)

  • What is it? The other universal package format.
  • Core Concept: “Shared Runtimes.” This is the brilliant compromise. Instead of bundling everything, Flatpaks bundle some things.
  • All Flatpaks can share a common set of “Runtimes,” like org.gnome.Platform/45 or org.kde.Platform/6.
  • So, you install the 1GB “GNOME 45 Runtime” once, and then every GNOME Flatpak app (which are tiny) will use it.
  • Pros:
    • Works on any Linux.
    • More decentralized. The main repo is Flathub, but anyone can host one.
    • More space-efficient than Snaps.
    • Sandboxed.
  • Cons:
    • Still larger and slightly slower than native apt/dnf packages.
  • Commands: flatpak install flathub spotify, flatpak update.

3. AppImage

  • What is it? The simplest concept. “One app = one file.”
  • Core Concept: It’s a “portable app” for Linux.
  • Pros:
    • You download one file, e.g., kdenlive.AppImage.
    • You make it executable: chmod +x kdenlive.AppImage.
    • You run it: ./kdenlive.AppImage.
    • It just runs. No installation. No admin rights needed.
  • Cons:
    • No automatic updates. You have to manually go to the website and download the new AppImage file.
    • No central repo. It’s the “wild west.”

Conclusion (The Right Tool for the Job)

You are now, officially, a Linux package management expert. You’ve gone from the “dependency hell” of tar.gz to the mastery of apt, dnf, and the “new world” of Flatpaks.

This isn’t a “vs.” battle. It’s a toolkit. Here is your new, professional workflow for managing software on any Linux system.

Your New Workflow:

  1. ALWAYS try to use your system’s native package manager first (apt on Ubuntu, dnf on Fedora). This is the most stable, secure, fast, and resource-efficient method.
    • apt cache search <app>
    • dnf search <app>
  2. IF the native package is too old (e.g., Ubuntu has an old version, but you need the new one)…
    • On Ubuntu: Look for an official PPA (Personal Package Archive) from the developer.
    • On RHEL/Fedora: Look for an official third-party repo (like epel-release or the Docker repo).
  3. IF it’s a graphical desktop app (like Spotify, VSCode, GIMP, OBS Studio)…
    • A Flatpak from Flathub is an excellent and preferred choice. It’s sandboxed, up-to-date, and won’t interfere with your system. Most “Software Store” apps are now Flatpaks.
  4. Snaps are also a good choice, especially if it’s the only one the developer provides (common with Ubuntu) or for certain server apps.
  5. AppImage is for when you just want to try an app once without “installing” it, or for running an app on a USB stick.
  6. Compiling from Source (./configure…) is your ABSOLUTE, FINAL, LAST RESORT. This is what you do when all other options have failed, or when you are a developer who needs to modify the code.

You’re no longer at the mercy of cryptic error messages. You are the admin. You understand the ecosystem, you have the tools, and you can now install, update, and manage any piece of software on any Linux machine with absolute confidence and precision.

Go forth and install.

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Your contribution powers free tutorials, hands-on labs, and security resources.

Why your support matters:
  • Writeup Access: Get complete writeup access within 12 hours
  • Zero paywalls: Keep the main content 100% free for learners worldwide

Perks for one-time supporters:
☕️ $5: Shoutout in Buy Me a Coffee
🛡️ $8: Fast-track Access to Live Webinars
💻 $10: Vote on future tutorial topics + exclusive AMA access

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

If you like this post, then please share it:

Linux 101

Discover more from The CyberSec Guru

Subscribe to get the latest posts sent to your email!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from The CyberSec Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading