Linux Package Management: Installing and Managing Software
Learn to install, update, and manage software on Linux systems. From apt and dnf to snap and flatpak, understand package managers across different distributions.
Why Package Management Matters
Package managers are how you install, update, and remove software on Linux. They handle dependencies automatically, verify package authenticity, and keep your system secure with updates.
Unlike Windows or macOS where you download installers from websites, Linux uses centralized repositories of tested, compatible software. Your package manager connects to these repos, resolves dependencies, and ensures everything works together.
Different Linux distributions use different package managers. Ubuntu and Debian use APT. Red Hat, Fedora, and CentOS use DNF (or older YUM). Understanding your distribution's package manager is essential for installing software, applying security updates, and maintaining your system.
This guide covers the essential package management commands across major Linux distributions. Learn these and you'll confidently install software, keep systems updated, and troubleshoot package issues.
apt vs yum vs dnf: Complete Comparison
The three main Linux package managers share the same concepts but differ in syntax and features. Here's everything side by side.
apt | yum | dnf | |
|---|---|---|---|
| Distros | Debian, Ubuntu, Linux Mint | RHEL 7, CentOS 7, older Fedora | Fedora, RHEL 8+, CentOS Stream |
| Install a package | apt install pkg | yum install pkg | dnf install pkg |
| Update package lists | apt update | yum check-update | dnf check-update |
| Upgrade all packages | apt upgrade | yum update | dnf upgrade |
| Remove a package | apt remove pkg | yum remove pkg | dnf remove pkg |
| Search packages | apt search term | yum search term | dnf search term |
| Show package info | apt show pkg | yum info pkg | dnf info pkg |
| Clean cache | apt clean | yum clean all | dnf clean all |
| Parallel downloads | No | No | Yes (default) |
| Transaction history / undo | No | Limited | Yes — dnf history undo N |
| Config location | /etc/apt/ | /etc/yum.conf | /etc/dnf/dnf.conf |
| Status | Current | Legacy (replaced by dnf) | Current — preferred |
yum actually runs dnf — yum is now a symlink. dnf's parallel downloads and transaction history make it significantly faster and safer than yum for large updates.Common Package Management Mistakes
Forgetting to Update Before Installing
The Problem: Running apt install or dnf install without updating package lists first can install outdated versions or fail if packages have been renamed or moved.
The Solution: Always run apt update (Ubuntu/Debian) or dnf check-update (RHEL/Fedora) before installing packages. Make it a habit: sudo apt update && sudo apt install package. This ensures you get the latest package information and versions.
Adding Untrusted Repositories
The Problem: Adding random PPAs or third-party repositories without verifying the source can compromise your system security. Malicious repos can install malware or override critical system packages.
The Solution: Only add repositories from trusted sources. Research the PPA maintainer or repository provider. Check if the package is available in official repos first. Remove repositories after installing if you only needed one package from them.
Not Cleaning Up After Installations
The Problem: Package managers cache downloaded packages and keep orphaned dependencies. Over time, /var/cache can fill up with gigabytes of old package files, wasting disk space.
The Solution: Regularly run apt autoremove && apt clean (Ubuntu/Debian) or dnf autoremove && dnf clean all (RHEL/Fedora). Set up a monthly cron job for cleanup on servers. Check disk usage with du -sh /var/cache/ periodically.
Mixing Package Managers Incorrectly
The Problem: Installing the same software via multiple package managers (apt + snap + manual install) creates conflicts, duplicate packages, and confusion about which version is running.
The Solution: Pick one package manager per application and stick with it. Check which version is actually running (which command) before installing. Use distribution packages for system software, snaps/flatpaks for user applications.
7 Essential Package Management Skills
These commands cover package management across Ubuntu/Debian (APT) and RHEL/Fedora (DNF), plus universal package managers.
Installing Packages with APT (Debian/Ubuntu)
APT is the package manager for Debian-based systems like Ubuntu. It handles dependencies automatically and connects to official repositories for software.
# Update package lists (always run first)
$ sudo apt update
# Install a package
$ sudo apt install nginx
# Install multiple packages
$ sudo apt install git curl vim
# Install without confirmation prompt
$ sudo apt install -y htop
# Reinstall corrupted package
$ sudo apt install --reinstall python3
# See what would be installed
$ sudo apt install --dry-run docker.io
# Full system upgrade
$ sudo apt update && sudo apt upgrade -y
# Clean up after install
$ sudo apt autoremove && sudo apt autocleanPro Tips: Always run apt update before installing packages to get the latest package information. Use apt instead of apt-get for interactive use - it has better output and progress bars. The -y flag skips confirmation prompts, useful for scripts.
Managing Packages with DNF (RHEL/Fedora)
DNF is the modern package manager for Red Hat, Fedora, and CentOS systems. It replaced YUM with better performance and cleaner dependency resolution.
# Install a package
$ sudo dnf install httpd
# Update all packages
$ sudo dnf upgrade
# Install group of packages
$ sudo dnf groupinstall "Development Tools"
# Find package providing a file
$ sudo dnf provides /usr/bin/git
# Remove package and dependencies
$ sudo dnf remove package
$ sudo dnf autoremove
# Clean cached data
$ sudo dnf clean all
# List available updates
$ dnf check-update
# Enable/disable repository
$ sudo dnf config-manager --set-enabled repo-name
$ sudo dnf config-manager --set-disabled repo-namePro Tips: DNF automatically resolves dependencies better than YUM. Use dnf history to see past transactions and undo them if needed. Enable only repositories you trust - third-party repos can cause conflicts.
Searching and Finding Packages
Before installing, you need to find packages. Search by name, description, or the files they provide. Different package managers have similar search capabilities.
# APT: Search for packages
$ apt search python
$ apt search "web server"
# APT: Show package details
$ apt show nginx
Package: nginx
Version: 1.18.0-6ubuntu14
Description: small, powerful, scalable web/proxy server
# APT: Find package containing file
$ apt-file search /usr/bin/git
git: /usr/bin/git
# DNF: Search packages
$ dnf search docker
# DNF: Search everything
$ dnf search all kubernetes
# DNF: Find what provides a command
$ dnf provides */netstat
net-tools-2.0-0.62.fc38.x86_64
# List installed packages matching pattern
$ apt list --installed | grep python
$ dnf list installed python*Pro Tips: Install apt-file on Ubuntu/Debian for file searching: sudo apt install apt-file && sudo apt-file update. Use wildcards in searches for broader results. Check package websites for detailed documentation before installing large packages.
Updating and Upgrading Your System
Keep your system secure and stable with regular updates. Understand the difference between updating package lists, upgrading packages, and distribution upgrades.
# APT: Full update workflow
$ sudo apt update
$ sudo apt upgrade -y
$ sudo apt full-upgrade
$ sudo apt autoremove
# APT: Show upgradable packages
$ apt list --upgradable
# APT: Upgrade specific package
$ sudo apt install --only-upgrade nginx
# DNF: Update system
$ sudo dnf upgrade
# DNF: Security updates only
$ sudo dnf upgrade --security
# DNF: Check for updates without installing
$ dnf check-update
# Unattended upgrades (Ubuntu)
$ sudo apt install unattended-upgrades
$ sudo dpkg-reconfigure unattended-upgrades
# Check if reboot needed (Ubuntu)
$ cat /var/run/reboot-requiredPro Tips: Set up automatic security updates on servers using unattended-upgrades (Debian/Ubuntu) or dnf-automatic (RHEL/Fedora). Always update before installing new packages. Some updates require a reboot - check /var/run/reboot-required.
Removing Packages and Cleaning Up
Uninstall packages cleanly and remove leftover dependencies. Free up disk space by cleaning package caches and removing orphaned packages.
# APT: Remove package
$ sudo apt remove nginx
# APT: Remove package and config
$ sudo apt purge nginx
# APT: Remove unused dependencies
$ sudo apt autoremove
# APT: Clean package cache
$ sudo apt clean
$ sudo apt autoclean
# DNF: Remove package
$ sudo dnf remove httpd
# DNF: Remove with dependencies
$ sudo dnf autoremove httpd
# DNF: Clean all caches
$ sudo dnf clean all
# Check what autoremove will remove
$ sudo apt autoremove --dry-run
# Find orphaned packages (Debian/Ubuntu)
$ deborphan
# Check disk space used by packages
$ du -sh /var/cache/apt/archives/
$ du -sh /var/cache/dnf/Pro Tips: Use purge instead of remove when completely removing software - it cleans config files too. Run autoremove regularly to free space. Be very careful with autoremove on production servers - review what will be removed first.
Managing Repositories and PPAs
Add third-party repositories to access software not in official repos. Understand repository priorities, GPG keys, and security implications.
# Ubuntu: Add PPA
$ sudo add-apt-repository ppa:user/ppa-name
$ sudo apt update
# Ubuntu: Remove PPA
$ sudo add-apt-repository --remove ppa:user/ppa-name
# Debian/Ubuntu: Add repository manually
$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
# Add GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# RHEL/CentOS: Enable EPEL
$ sudo dnf install epel-release
# Enable/disable repository
$ sudo dnf config-manager --set-enabled repo-name
$ sudo dnf config-manager --set-disabled repo-name
# List all repositories
$ apt-cache policy
$ dnf repolist all
# Check package repository source
$ apt-cache policy package
$ dnf info packagePro Tips: Stick to official repos when possible - they're tested and secure. If using PPAs, research the maintainer first. Enable third-party repos only when needed, disable after installing. Keep a list of added repos for documentation.
Universal Package Managers: Snap and Flatpak
Snap and Flatpak provide distribution-independent packages that work across different Linux distributions. They include all dependencies and run in isolated environments.
# Snap: Install package
$ sudo snap install package-name
# Snap: Install from specific channel
$ sudo snap install package --edge
# Snap: List installed snaps
$ snap list
# Snap: Update all snaps
$ sudo snap refresh
# Snap: Remove snap
$ sudo snap remove package
# Flatpak: Add Flathub repository
$ flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# Flatpak: Install application
$ flatpak install flathub com.spotify.Client
# Flatpak: Run application
$ flatpak run com.spotify.Client
# Flatpak: Update all
$ flatpak update
# Flatpak: List installed
$ flatpak list
# Check snap/flatpak disk usage
$ du -sh /var/lib/snapd/
$ du -sh /var/lib/flatpak/Pro Tips: Use traditional package managers (apt/dnf) for system packages, snap/flatpak for desktop applications. Flatpak generally has better desktop integration. Snaps auto-update which is good for security but can break things - check settings to control updates.
Your First Steps with Package Management
Build confidence with package management through these practical steps.
Learn Your Distribution's Package Manager
Identify if you're on Debian/Ubuntu (use apt) or RHEL/Fedora/CentOS (use dnf). Practice the core commands: update, install, remove, search. Run apt update or dnf check-update, then install a simple package like htop to get comfortable with the workflow.
Set Up a Regular Update Schedule
Create a habit of updating weekly. Add a calendar reminder or set up automatic security updates. Practice the full update sequence: update package lists, review what will be upgraded, apply updates, clean up with autoremove. This keeps your system secure and stable.
Practice Search and Information Commands
Before installing packages, learn to search and investigate. Practice apt search, apt show, dnf search, and dnf info commands. Look up a package you want to install, read its description, check dependencies, and verify it's from official repos before installing.
Go Deeper with Package Management
This guide covers essential package management. The Practical Linux Handbook includes advanced topics, repository management, package building, and complete system administration.
What You'll Learn:
- Complete package management (apt, dnf, rpm, dpkg)
- Repository configuration and management
- Package building and distribution
- Dependency resolution and troubleshooting
- System updates and security patches
Beyond Package Management:
- 70+ Linux commands with detailed examples
- File operations and permissions
- Process management and monitoring
- Network administration and troubleshooting
- 3 bonus editor cheat sheets (Vim, Nano, Emacs)
Continue Your Linux Journey
Frequently Asked Questions
What is package management in Linux?
Package management is a system for installing, updating, and removing software. It handles dependencies automatically — when you install a program that needs other libraries, the package manager fetches them for you. Common tools: apt (Debian/Ubuntu), dnf/yum (Fedora/RHEL), and pacman (Arch Linux).
What is the difference between apt and yum?
apt is the package manager for Debian-based distros like Ubuntu and Linux Mint. yum is for RHEL-based distros like older CentOS and Fedora. Commands differ: `apt install package` vs `yum install package`. Modern Fedora and RHEL 8+ use dnf, which replaced yum.
When should I use dnf vs apt?
You don't choose — your distribution determines which is available. Use dnf on Fedora, RHEL 8+, and CentOS Stream. Use apt on Ubuntu, Debian, and Linux Mint. dnf is faster than yum and handles dependency resolution better.
What is the difference between apt and apt-get?
apt is the modern, user-friendly frontend with a progress bar and cleaner output. apt-get is the lower-level, stable tool preferred in scripts and automation. For interactive terminal use, apt is better. For shell scripts, use apt-get since its output format is guaranteed not to change.
How do I install a package with apt, yum, or dnf?
With apt: `sudo apt install package-name`. With yum: `sudo yum install package-name`. With dnf: `sudo dnf install package-name`. All three will show what will be installed and ask for confirmation before proceeding.
Ready to Master Package Management?
Join thousands who've learned to confidently install, update, and manage Linux software with The Practical Linux Handbook.