Jun 15, 2026 · 4 min read

Mastering Linux Package Management: apt, yum/dnf, and snap

Introduction

Struggling to keep your Linux software up to date? In this quick guide we’ll master apt, yum/dnf, and snap to install, update, and remove packages across any distro. Keeping your system patched not only brings new features but also critical security fixes.


1. APT Basics (Debian/Ubuntu)

Core commands

# Refresh the local package index
sudo apt update

# Install a package (example: nginx)
sudo apt install nginx

# Remove a package
sudo apt remove nginx

# Upgrade all installed packages (non‑interactive)
sudo apt upgrade -y
  • update pulls the latest package lists from the repositories defined in /etc/apt/sources.list and /etc/apt/sources.list.d/.

  • install resolves dependencies automatically and writes the transaction to the dpkg database.

  • remove only deletes the package files; use sudo apt purge <pkg> to also erase configuration files.

  • upgrade applies available updates without changing the package set. For a full distribution upgrade use sudo apt full-upgrade.


2. YUM / DNF Usage (RHEL, CentOS, Fedora)

When to use which

  • yum is the default package manager for RHEL/CentOS 7 and older.

  • dnf replaces yum on Fedora, CentOS 8+, and newer RHEL versions. It offers faster dependency solving and a more stable API.

Core commands (identical syntax)

# Install a web server (httpd)
sudo yum install httpd   # or sudo dnf install httpd

# Remove the web server
sudo yum remove httpd    # or sudo dnf remove httpd

# Update the entire system
sudo yum update -y      # or sudo dnf upgrade -y

Both tools read repository definitions from /etc/yum.repos.d/. They also support GPG verification of packages out‑of‑the‑box.


3. Snap Quick‑Start (Canonical Snap Store)

Snap packages are containerized, self‑contained binaries that run on most Linux distributions.

# Install Visual Studio Code with classic confinement (needed for dev tools)
sudo snap install code --classic

# Refresh all installed snaps (auto‑updates happen daily, but you can force it)
sudo snap refresh code

# Remove a snap
sudo snap remove code
  • auto‑updates are enabled by default, reducing maintenance overhead.

  • confinement isolates the application; --classic relaxes it for tools that need broader system access.


4. Repository Management Tips

Manager Repo config location Common commands
apt /etc/apt/sources.list & /etc/apt/sources.list.d/ add-apt-repository
yum/dnf /etc/yum.repos.d/ (individual .repo files) yum-config-manager, dnf config-manager
snap Snap Store (cloud‑hosted) snap install

Adding third‑party repositories safely

# Ubuntu PPA example
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

# RHEL/CentOS custom repo (yum)
sudo yum-config-manager --add-repo=http://example.repo/repo.repo

# Fedora custom repo (dnf)
sudo dnf config-manager --add-repo=http://example.repo/repo.repo
  1. Verify GPG keys – Import the maintainer’s public key and ensure the repository metadata is signed.

  2. Prefer official repos – Third‑party repos can introduce conflicting versions or unwanted dependencies.

  3. Pin priorities – Use apt-pinning or yum/dnf priority= to keep core distro packages ahead of external ones.


5. Best Practices & Pitfalls

Best practices

  • Run updates regularly – Schedule a daily apt upgrade or dnf upgrade via cron or systemd timers.

  • Test before production – Use a staging VM or container to validate major version upgrades.

  • Leverage snapshots – On Btrfs/ZFS, snapshot the root filesystem before large upgrades; on Ubuntu, apt supports apt-get autoremove to clean stale packages.

  • Audit installed packagesapt list --installed or dnf repoquery --installed helps identify orphaned libraries.

Common pitfalls

  • Mixing package managers for the same software (e.g., installing nginx via apt and snap) can cause port conflicts.

  • Ignoring GPG warnings may expose the system to tampered packages.

  • Using sudo apt upgrade on a release upgrade scenario – you need dist-upgrade/full-upgrade instead.

  • Over‑reliance on snap for server workloads – snaps add a layer of abstraction; ensure performance impact is acceptable.


6. Conclusion & Call to Action

Regular updates keep your Linux environment secure and performant. By mastering the native package managers—apt, yum/dnf, and snap—you gain fine‑grained control over installations, rollbacks, and repository handling.

💡 Which manager do you use most? Share your favorite tip in the comments, and grab the full cheat‑sheet from the description below!

Related Posts

Linux Commands Every Developer Should Know

A practical guide to the terminal commands that show up in daily development, debugging, and server work.

Useful Linux Commands for Logs and File Search

A production-style walkthrough of find, tail, journalctl, grep, and awk for server troubleshooting.

Jul 06, 2026

Demystifying Kubernetes Service Discovery

Unlock the full potential of Kubernetes with our comprehensive guide to service discovery, enabling seamless communication between services within your cluster.

Jul 05, 2026

Harnessing the Power of Kubernetes: Pods and Deployments Demystified

Discover how Kubernetes Pods and Deployments provide powerful tools for managing and scaling applications efficiently within containerized environments.