HxHippy

Package Management Across Distros

Install, update, and manage software with apt, dnf, pacman, and more.

Last updated: 2024-12-18

Every Linux distribution has a package manager. Learn the commands for the major package managers.

Package Manager Comparison

Task Debian/Ubuntu (apt) RHEL/Fedora (dnf) Arch (pacman)
Update index apt update dnf check-update pacman -Sy
Upgrade all apt upgrade dnf upgrade pacman -Su
Install apt install pkg dnf install pkg pacman -S pkg
Remove apt remove pkg dnf remove pkg pacman -R pkg
Search apt search pkg dnf search pkg pacman -Ss pkg
Info apt show pkg dnf info pkg pacman -Si pkg

APT (Debian, Ubuntu, Mint)

Basic Operations

# Update package lists
sudo apt update

# Upgrade all packages
sudo apt upgrade

# Full upgrade (handles dependencies better)
sudo apt full-upgrade

# Install package
sudo apt install nginx

# Install multiple packages
sudo apt install nginx php php-fpm

# Install specific version
sudo apt install nginx=1.18.0-0ubuntu1

# Remove package (keep config)
sudo apt remove nginx

# Remove package and config
sudo apt purge nginx

# Remove unused dependencies
sudo apt autoremove

# Search for packages
apt search nginx
apt-cache search nginx

# Show package info
apt show nginx

Advanced APT

# List installed packages
apt list --installed

# List upgradable packages
apt list --upgradable

# Show package files
dpkg -L nginx

# Find which package provides a file
dpkg -S /usr/bin/nginx
apt-file search /usr/bin/nginx  # needs apt-file installed

# Download without installing
apt download nginx

# Install from .deb file
sudo dpkg -i package.deb
sudo apt install -f  # Fix dependencies

# Pin package version (prevent upgrades)
sudo apt-mark hold nginx
sudo apt-mark unhold nginx

# Clean package cache
sudo apt clean
sudo apt autoclean

APT Repositories

# List repositories
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/

# Add PPA (Ubuntu)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

# Remove PPA
sudo add-apt-repository --remove ppa:deadsnakes/ppa

# Add custom repository
echo "deb https://repo.example.com stable main" | \
    sudo tee /etc/apt/sources.list.d/example.list

# Add GPG key
curl -fsSL https://repo.example.com/gpg.key | \
    sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg

DNF/YUM (RHEL, Fedora, CentOS, Rocky)

Basic Operations

# Update package lists
sudo dnf check-update

# Upgrade all packages
sudo dnf upgrade
# or
sudo dnf update

# Install package
sudo dnf install nginx

# Install from local RPM
sudo dnf install ./package.rpm

# Remove package
sudo dnf remove nginx

# Search packages
dnf search nginx

# Show package info
dnf info nginx

# List installed packages
dnf list installed

Advanced DNF

# Show package history
dnf history

# Rollback transaction
sudo dnf history undo <transaction_id>

# List package files
rpm -ql nginx

# Find which package provides a file
dnf provides /usr/bin/nginx

# Enable/disable repository
sudo dnf config-manager --enable epel
sudo dnf config-manager --disable epel

# Add repository
sudo dnf config-manager --add-repo https://repo.example.com/repo.repo

# Clean cache
sudo dnf clean all

DNF Groups

# List available groups
dnf group list

# Install group
sudo dnf group install "Development Tools"

# Remove group
sudo dnf group remove "Development Tools"

Pacman (Arch, Manjaro)

Basic Operations

# Sync database
sudo pacman -Sy

# Upgrade all packages
sudo pacman -Syu

# Install package
sudo pacman -S nginx

# Remove package
sudo pacman -R nginx

# Remove package + dependencies
sudo pacman -Rs nginx

# Remove package + config
sudo pacman -Rn nginx

# Search packages
pacman -Ss nginx

# Show package info
pacman -Si nginx

# List installed packages
pacman -Q

Advanced Pacman

# List explicitly installed packages
pacman -Qe

# List orphan packages
pacman -Qdt

# Remove orphans
sudo pacman -Rs $(pacman -Qdtq)

# Find which package owns a file
pacman -Qo /usr/bin/nginx

# List package files
pacman -Ql nginx

# Clean package cache
sudo pacman -Sc  # Remove old versions
sudo pacman -Scc # Remove all cache

# Query remote package
pacman -Si nginx

# Query local package
pacman -Qi nginx

AUR (Arch User Repository)

# Install yay (AUR helper)
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

# Use yay like pacman
yay -S package-name
yay -Syu  # Update all including AUR

Universal Package Managers

Snap

# Install snap
sudo apt install snapd

# Search packages
snap find nginx

# Install package
sudo snap install code --classic

# List installed
snap list

# Update all
sudo snap refresh

# Remove package
sudo snap remove code

Flatpak

# Install flatpak
sudo apt install flatpak

# Add Flathub repository
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# Search packages
flatpak search spotify

# Install package
flatpak install flathub com.spotify.Client

# Run application
flatpak run com.spotify.Client

# Update all
flatpak update

# Remove
flatpak uninstall com.spotify.Client

AppImage

# Download AppImage
wget https://example.com/app.AppImage

# Make executable and run
chmod +x app.AppImage
./app.AppImage
beginner System Administration 20 min read

Related Tutorials

aptdnfpacmanyumpackage managerlinux packages