Linux Package Management: apt, dnf, and snap Explained

Learn how to install, update, and remove software in Linux using apt (Ubuntu/Debian), dnf (Red Hat/Fedora), and snap. Your complete beginner's guide.

Linux Package Management: apt, dnf, and snap Explained
📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free

On Windows, installing software means: Google it → Find a website → Hope it’s not malware → Click “Next” 12 times. On Linux, it’s one command. And it’s safer.

Introduction

A package manager is one of Linux’s most underrated superpowers. It’s a command-line tool that can install, update, verify, and remove software — automatically handling all dependencies for you. No hunting for installers, no sketchy download sites.

What You'll Learn
  • What a package manager actually does under the hood
  • apt commands for Ubuntu and Debian
  • dnf commands for Red Hat, Fedora, and Rocky Linux
  • snap for cross-distro universal packages
  • How to keep your system clean and updated
Mental Model: The App Store

A package manager is like your phone’s App Store — but for your entire system:

  • The repository = the App Store’s catalog (thousands of free, verified apps)
  • apt install nginx = tapping “Install” on an app
  • apt update = refreshing the catalog to see new versions
  • Dependencies = apps that require other apps to work (handled automatically)

The key difference? Everything is verified, free, and updated forever.

How Package Management Works

Package management flow from repository to local filesystem
When you run 'apt install', here's exactly what happens behind the scenes.

The flow in plain English:

  1. apt update — Downloads the latest catalog from the repository server
  2. apt install nginx — Finds nginx in the catalog, downloads it and all its dependencies
  3. Packages go into a local cache (/var/cache/apt/archives/)
  4. Files are installed into the correct system locations (/usr/bin/, /etc/, etc.)

apt — Ubuntu, Debian, Kali, Mint

apt (Advanced Package Tool) is the dominant package manager on Debian-based distributions.

The Essential Workflow

Always update before installing:

sudo apt update

Refresh the package list from repositories

beginner
sudo apt upgrade

Upgrade all installed packages to latest versions

beginner
update ≠ upgrade

apt update only refreshes the list — it downloads no packages.
apt upgrade actually downloads and installs new versions.
Run update first, then upgrade.

sudo apt install nginx

Install nginx web server

beginner
sudo apt install nginx curl git -y

Install multiple packages at once (-y skips confirmation)

beginner
sudo apt remove nginx

Remove nginx (keeps config files)

beginner
sudo apt purge nginx

Remove nginx AND all its config files

beginner
apt search nginx

Search available packages by name

beginner
apt show nginx

Show details about a package

beginner

Keeping the System Clean

sudo apt autoremove

Remove packages no longer needed by anything else

beginner
sudo apt clean

Delete all cached package files (free up disk space)

beginner

Show what’s installed:

dpkg -l

List all installed packages

beginner
dpkg -l | grep nginx

Check if nginx is installed

beginner

dnf — Red Hat, Fedora, Rocky, AlmaLinux

dnf (Dandified YUM) replaced the older yum on modern Red Hat-based systems. The commands map 1:1 with apt.

apt commanddnf equivalent
apt updatednf check-update
apt install Xdnf install X
apt remove Xdnf remove X
apt upgradednf upgrade
apt search Xdnf search X
apt autoremovednf autoremove
sudo dnf check-update

Check for available updates

beginner
sudo dnf install nginx

Install nginx

beginner
sudo dnf remove nginx

Remove nginx

beginner
sudo dnf upgrade

Upgrade all packages

beginner

Check what’s installed:

rpm -qa

List all installed packages (RPM)

beginner
rpm -q nginx

Check if nginx is installed

beginner

snap — Universal Packages for Any Distro

snap packages are self-contained — they bundle their own dependencies so the same snap works on Ubuntu, Fedora, Arch, everywhere. They’re sandboxed for security.

When to use snap

Use snap when:

  • You need the latest version of an app (e.g., VS Code, Discord, Firefox)
  • You’re on a distro where the package is outdated in the official repos
  • You want easy rollback to previous versions
snap find vscode

Search for VS Code in the snap store

beginner
sudo snap install code --classic

Install VS Code (--classic for filesystem access)

beginner
sudo snap remove code

Remove VS Code snap

beginner
sudo snap refresh

Update all installed snaps

beginner
snap list

List all installed snaps

beginner
sudo snap revert code

Roll back VS Code to its previous version

beginner
Snap Trade-offs

Snaps start slightly slower than native packages (they mount a filesystem image). For desktop apps, this is fine. For servers, prefer apt/dnf.


Real-World Scenarios

Scenario 1: Set Up a New Server

# Update everything first
sudo apt update && sudo apt upgrade -y

# Install your stack
sudo apt install -y nginx postgresql git curl ufw

# Clean up
sudo apt autoremove -y && sudo apt clean

Scenario 2: Find Which Package Owns a File

dpkg -S /usr/bin/nginx

Which package installed this file? (Debian/Ubuntu)

beginner
rpm -qf /usr/sbin/nginx

Which package installed this file? (Red Hat)

beginner

Scenario 3: Install a .deb file Manually

sudo dpkg -i package.deb

Install a downloaded .deb file

beginner
sudo apt -f install

Fix broken dependencies after dpkg

beginner

The Golden Rules of Package Management

  1. Always sudo apt update before installing — otherwise you get outdated versions.
  2. Use purge not remove when you’re done with software permanently.
  3. Run autoremove regularly — orphaned dependencies waste disk space.
  4. Don’t mix sources — stick to official repos when possible. Third-party PPAs can break things.

Hands-On Challenge

  1. Run sudo apt update and count how many packages are listed.
  2. Install tree with sudo apt install tree.
  3. Run tree /etc/nginx (if nginx is installed) to see its config structure.
  4. Remove tree with sudo apt remove tree.
  5. Run sudo apt autoremove to clean up.

Key Takeaways

  • Package managers handle installation, updates, and removal — with dependency resolution built in.
  • apt = Ubuntu/Debian. dnf = Red Hat/Fedora. snap = any distro.
  • Always apt update before installing to get the latest package information.
  • Use apt purge (not remove) to completely uninstall software including configs.
  • Run apt autoremove regularly to keep your system clean.
🧠

Test Your Knowledge

Take a quick 4-question quiz to check your understanding.

📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free
Type to start searching...