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.

70+
Essential Commands
190+
Practical Examples
30+
Topics Covered
4.9/5
Reader Rating

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.

aptyumdnf
DistrosDebian, Ubuntu, Linux MintRHEL 7, CentOS 7, older FedoraFedora, RHEL 8+, CentOS Stream
Install a packageapt install pkgyum install pkgdnf install pkg
Update package listsapt updateyum check-updatednf check-update
Upgrade all packagesapt upgradeyum updatednf upgrade
Remove a packageapt remove pkgyum remove pkgdnf remove pkg
Search packagesapt search termyum search termdnf search term
Show package infoapt show pkgyum info pkgdnf info pkg
Clean cacheapt cleanyum clean alldnf clean all
Parallel downloadsNoNoYes (default)
Transaction history / undoNoLimitedYes — dnf history undo N
Config location/etc/apt//etc/yum.conf/etc/dnf/dnf.conf
StatusCurrentLegacy (replaced by dnf)Current — preferred
Note: On modern RHEL/Fedora systems, typing 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.

Essential APT Commands: apt install package: Install a package apt update: Refresh package lists from repositories apt upgrade: Upgrade all installed packages apt full-upgrade: Upgrade with dependency changes apt autoremove: Remove unused dependencies Common Patterns: Install multiple packages: apt install pkg1 pkg2 pkg3 Reinstall package: apt install --reinstall package Install specific version: apt install package=version Simulate install: apt install --dry-run package Repository Management: Package lists stored in /var/lib/apt/lists/ Sources defined in /etc/apt/sources.list Additional sources in /etc/apt/sources.list.d/
# 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 autoclean

Pro 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.

Essential DNF Commands: dnf install package: Install a package dnf update: Update all packages dnf upgrade: Same as update (preferred term) dnf remove package: Uninstall a package dnf autoremove: Remove unneeded dependencies Information Commands: dnf info package: Show package details dnf list installed: List all installed packages dnf provides file: Find package containing file dnf repolist: List enabled repositories DNF vs YUM: DNF is faster with better dependency solving Backward compatible (yum commands still work) Better error messages and output Lower memory usage
# 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-name

Pro 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 Commands: apt search keyword: Search package names and descriptions apt-cache search keyword: Alternative search apt show package: Display detailed package info apt-file search file: Find package containing file DNF Search Commands: dnf search keyword: Search names and summaries dnf search all keyword: Search names, summaries, descriptions dnf info package: Show package information dnf provides */filename: Find package with file Search Tips: Use quotes for multi-word searches Pipe to grep for filtering results Check package descriptions before installing Look for -dev or -devel packages for development
# 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.

Update vs Upgrade: Update: Refresh package lists from repositories Upgrade: Install newer versions of packages Full-upgrade/dist-upgrade: Handle dependency changes APT Update Process: 1. apt update: Fetch latest package info 2. apt upgrade: Upgrade existing packages 3. apt full-upgrade: Upgrade with dependency changes 4. apt autoremove: Clean unused dependencies DNF Update Process: dnf check-update: See available updates dnf upgrade: Update all packages dnf upgrade --security: Security updates only dnf distro-sync: Sync to latest available versions Best Practices: Update regularly (weekly for servers) Test updates in dev before production Check changelogs for major updates Keep backups before major 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-required

Pro 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 Removal Commands: apt remove package: Remove package, keep config apt purge package: Remove package and config apt autoremove: Remove unused dependencies apt autoclean: Remove old cached packages apt clean: Remove all cached packages DNF Removal Commands: dnf remove package: Uninstall package dnf autoremove: Remove orphaned dependencies dnf clean all: Clear all cached data dnf clean packages: Remove cached packages What Gets Removed: remove/purge: Package files autoremove: Dependencies no longer needed clean: Downloaded .deb/.rpm files Configuration files (purge only) Safety Tips: Check what will be removed before confirming Some packages are critical (be careful!) Use autoremove after removing large 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.

APT Repository Management: add-apt-repository: Add PPA (Ubuntu) Repository files: /etc/apt/sources.list.d/ GPG keys: For repository verification Priority: Control which repo takes precedence DNF Repository Management: dnf config-manager: Enable/disable repos Repository files: /etc/yum.repos.d/ GPG keys: Verify package authenticity Repo priorities: Control package sources Security Considerations: Only add trusted repositories Verify GPG keys before installing Third-party repos can conflict Some repos override system packages Common Third-Party Repos: EPEL (Extra Packages for Enterprise Linux) RPM Fusion (Fedora multimedia) PPAs (Ubuntu Personal Package Archives)
# 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 package

Pro 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 (by Canonical): Works on Ubuntu and many other distros Automatic updates by default Sandboxed applications Snap Store for package discovery Larger package sizes (includes dependencies) Flatpak (by Freedesktop): Works across most Linux distributions Sandboxed with Bubblewrap Flathub repository Better desktop integration Runtime environments shared When to Use Universal Packages: App not in distribution repos Need latest version (not distro default) Want automatic updates Require sandboxing for security Cross-distribution compatibility Drawbacks: Larger disk usage Slower startup times Permission complexity Some desktop integration issues
# 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.

1

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.

2

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.

3

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)
4.9/5
Average Rating
127
Reader Reviews
#1
Bestseller

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.