Linux Package Management: apt, yum, dnf, and snap Explained
Package management is the process of installing, updating, removing, and maintaining software on a Linux system.
Different Linux distributions use different package managers, but they all simplify software installation by automatically handling dependencies.
This guide explains the most popular Linux package managers including apt, yum, dnf, and snap with practical examples.
Concept Overview
Instead of downloading software from websites, Linux installs applications from software repositories using package managers.
Package managers ensure software is authentic, up-to-date, and compatible with your Linux distribution.
Popular Linux Package Managers
1. apt – Package manager used by Debian, Ubuntu, Linux Mint, and related distributions.
2. yum – Traditional package manager for older CentOS and Red Hat Enterprise Linux versions.
3. dnf – Modern replacement for yum used by Fedora, RHEL, AlmaLinux, and Rocky Linux.
4. snap – Universal package management system developed by Canonical.
Managing Packages with apt
The apt command is the default package manager for Debian-based Linux distributions.
sudo apt update
sudo apt upgrade
sudo apt install nginx
sudo apt remove nginx
sudo apt purge nginx
sudo apt autoremove
apt list --installed
Explanation
apt update refreshes the package database.
apt upgrade installs available package updates.
apt install installs new software packages.
apt remove removes software while keeping configuration files.
apt purge removes both software and its configuration files.
apt autoremove deletes unnecessary dependency packages.
Managing Packages with yum
yum is commonly used on older Red Hat Enterprise Linux and CentOS systems.
sudo yum check-update
sudo yum update
sudo yum install httpd
sudo yum remove httpd
yum list installed
Explanation
yum downloads packages from configured repositories and automatically resolves dependencies.
Although still available on some systems, yum has largely been replaced by dnf.
Managing Packages with dnf
dnf is the modern package manager used by Fedora and current Red Hat-based Linux distributions.
sudo dnf check-update
sudo dnf upgrade
sudo dnf install nginx
sudo dnf remove nginx
dnf list installed
dnf search docker
Explanation
dnf provides faster dependency resolution, improved performance, and better package management compared to yum.
Most yum commands continue to work because yum is often linked to dnf for compatibility.
Managing Packages with snap
Snap packages are self-contained applications that include their required dependencies.
snap find vlc
sudo snap install vlc
snap list
sudo snap refresh
sudo snap remove vlc
Explanation
Snap packages can run on multiple Linux distributions without modification.
Applications are isolated from the system using sandboxing to improve security.
Searching for Packages
apt search nginx
yum search nginx
dnf search nginx
snap find nginx
Package managers provide search commands that help locate software before installation.
Viewing Package Information
apt show nginx
dnf info nginx
yum info nginx
snap info vlc
These commands display package descriptions, versions, dependencies, and repository information.
Example Workflow
Update the package database.
Search for the desired software package.
Install the application.
Verify installation by checking installed packages.
Update packages regularly to receive security fixes.
Remove unused packages to free disk space.
Comparison of Package Managers
apt is designed for Debian-based distributions.
yum supports older Red Hat Enterprise Linux and CentOS systems.
dnf is the recommended package manager for modern Red Hat-based distributions.
snap provides cross-distribution application packages with sandboxing.
Applications
Installing development tools and programming languages.
Managing web servers, databases, and cloud software.
Keeping Linux systems updated with security patches.
Automating software installation through shell scripts.
Managing enterprise Linux servers.
Advantages
Automatically resolves software dependencies.
Provides secure software from trusted repositories.
Simplifies software installation, updates, and removal.
Supports automated package management for servers.
Limitations
Different Linux distributions use different package managers.
Snap packages may consume more disk space because they bundle dependencies.
Repository availability varies between Linux distributions.
Best Practices
Always update the package database before installing new software.
Install packages only from trusted repositories.
Remove unused packages regularly to keep the system clean.
Keep installed software updated to receive security and bug fixes.
Mastering Linux package management is essential for Linux administrators, developers, DevOps engineers, and anyone working with Linux systems.