Skip to main content
⚑ OpenDevDocs
Linux
linuxlinuxGuideBeginner

Linux Package Management (apt, dnf, apk)

Install, update, upgrade, and manage operating system packages across Ubuntu/Debian (apt), RedHat/Fedora (dnf), and Alpine Linux (apk).

Verified: 2026-09-30
Tested on:linux Ubuntu 24.04 / Alpine 3.20
Platforms:
linux
#linux#package-manager#apt#dnf#apk#devops

Overview

Linux package managers download pre-compiled software binaries, resolve dependency trees, and handle automated security updates.


1. Debian & Ubuntu (apt)

# Update repository package metadata list
sudo apt update

# Upgrade all installed packages to latest versions
sudo apt upgrade -y

# Install new packages
sudo apt install -y curl git nginx build-essential

# Remove a package (keeps config files)
sudo apt remove nginx

# Purge package and all associated configuration files
sudo apt purge nginx

# Remove orphaned dependencies no longer needed
sudo apt autoremove -y

# Clean downloaded .deb cache
sudo apt clean

2. RHEL / CentOS / Rocky / Fedora (dnf / yum)

# Check for updates and upgrade system
sudo dnf upgrade -y

# Install packages
sudo dnf install -y nginx git

# Remove package
sudo dnf remove -y nginx

3. Alpine Linux (apk) (Docker Containers)

# Update package index and install without caching tarballs (keeps Docker image small)
apk update && apk add --no-cache curl ca-certificates bash

# Remove package
apk del curl

Command Quick Reference

ActionUbuntu/Debian (apt)RHEL/Fedora (dnf)Alpine (apk)
Update Indexapt updatednf check-updateapk update
Upgrade Systemapt upgradednf upgradeapk upgrade
Install Packageapt install <pkg>dnf install <pkg>apk add <pkg>
Remove Packageapt remove <pkg>dnf remove <pkg>apk del <pkg>
Search Packageapt search <term>dnf search <term>apk search <term>

On this page