G
GuideDevOps
Lesson 9 of 17

Package Management

Part of the Linux Fundamentals tutorial series.

Repositories and Packages

In Linux, you rarely download installers from websites. Instead, you use a Package Manager that downloads verified, compiled software from official repositories. This gives you:

  • Security — packages are signed and verified
  • Updatesapt update && apt upgrade updates everything at once
  • Clean removalapt remove cleanly uninstalls, including dependencies

Debian / Ubuntu — APT

The Advanced Package Tool (apt) manages .deb packages on Debian-based systems (Ubuntu, Debian, Linux Mint).

Essential Commands

# Update the local package index (always do this before installing)
$ sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Reading package lists... Done
Building dependency tree... Done
All packages are up to date.
 
# Upgrade all installed packages to their latest versions
$ sudo apt upgrade -y
Reading package lists... Done
Building dependency tree... Done
The following packages will be upgraded:
  openssl 2 packages upgraded, 0 newly installed, 0 to remove.
Need to get 2.5 MB of archives.
After this operation, 156 kB of additional disk space will be used.
 
# Full upgrade (can remove packages to resolve dependencies)
$ sudo apt full-upgrade -y

Installing and Removing Software

# Install a package
$ sudo apt install nginx -y
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  nginx nginx-common nginx-core
0 upgraded, 3 newly installed, 0 to remove.
Setting up nginx ...
 
# Install multiple packages at once
$ sudo apt install curl git vim -y
 
# Install specific version
$ sudo apt install nginx=1.18.0-6ubuntu14
 
# Remove a package (keeps configuration files)
$ sudo apt remove nginx
 
# Remove package AND delete its config files
$ sudo apt purge nginx
 
# Remove unused packages (orphaned dependencies)
$ sudo apt autoremove -y

Searching for Packages

# Search for a package by name or description
$ apt search "web server"
Sorting... Done
Full Text Search... Done
nginx/jammy,now 1.18.0-6ubuntu14 amd64 [installed]
  nginx high performance web server
 
apache2/jammy,now 2.4.52-1ubuntu3 amd64 [installed]
  Apache HTTP Server
 
# Show package details
$ apt show nginx
Package: nginx
Version: 1.18.0-6ubuntu14
Section: httpd
Priority: optional
Description: nginx high performance web server
Homepage: https://nginx.org
 
# Check if a package is installed
$ apt list --installed | grep nginx
nginx/jammy,now 1.18.0-6ubuntu14 amd64 [installed]

Package States

StateMeaning
iiInstalled
rcRemoved but config files remain
iUUnpacked but not configured
pnPurged (never installed)
# List installed packages
$ dpkg -l | head -10
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version              Architecture Description
+++-=============================-====================-============-===================================
ii  adduser                       3.131ubuntu1        all          add and remove users and groups
ii  apt                           2.4.8               amd64        commandline package manager
ii  bash                          5.1-6ubuntu1        amd64        GNU Bourne Again SHell

Red Hat / CentOS / Fedora — DNF

Modern RHEL-based systems use DNF (Dandified YUM) to manage .rpm packages.

# Install software
$ sudo dnf install httpd -y
Last metadata expiration check: 0:01:23 ago on Thu Apr 10 09:00:00 2026.
Dependencies resolved.
================================================================================
 Package        Arch       Version        Repository       Size
================================================================================
Installing:
 httpd          x86_64     2.4.37-43     rhel-8-baseos   1.4 M
...
Complete!
 
# Update all packages
$ sudo dnf update -y
 
# Remove a package
$ sudo dnf remove httpd -y
 
# Search for packages
$ dnf search nginx
# or
$ dnf list | grep nginx
 
# Show package info
$ dnf info httpd

YUM (Legacy RHEL 6/7)

# Same commands with yum
$ sudo yum install nginx -y
$ sudo yum update -y
$ sudo yum remove nginx -y
$ sudo yum search nginx

Alpine Linux — APK

Alpine uses apk — the fastest package manager. It's the standard in Docker containers because images are so lightweight.

# Install a package (no cache — ideal for Docker)
$ apk add --no-cache python3
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
(1/10) Installing python3 (3.11.7-r0)
...
(10/10) Installing python3 (3.11.7-r0)
OK: 65 MiB
 
# Search for packages
$ apk search nginx
 
# Show info about a package
$ apk info nginx
nginx-1.24.0-r0 description:
HTTP and reverse proxy server
 
# List installed packages
$ apk list --installed
 
# Remove a package
$ apk del nginx
 
# Update all packages
$ apk upgrade

Managing Repositories

APT — Adding a PPA (Personal Package Archive)

# Add a repository (PPA)
$ sudo add-apt-repository ppa:nginx/stable
$ sudo apt update
$ sudo apt install nginx
 
# Add a repository by source line
$ sudo apt add-apt-repository "deb http://repo.example.com/ stable main"

APT — Adding a Repository Key and Source

# Add Docker's official repository (example)
$ sudo apt install ca-certificates curl gnupg
 
$ sudo install -m 0755 -d /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
 
$ echo "deb [arch=$(dpkg --print-architecture) \
  signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list
 
$ sudo apt update
$ sudo apt install docker-ce

Checking Package Dependencies

# APT — show what a package requires
$ apt depends nginx
nginx
  Depends: nginx-core
  Depends: nginx-common
  Depends: libc6
  Depends: libpcre3
 
# APT — show what a package provides
$ apt rdepends nginx
nginx reverse depends:
  apache2
  (none)

System Updates as a DevOps Workflow

Automated Security Updates

# Install unattended-upgrades (Ubuntu/Debian)
$ sudo apt install unattended-upgrades -y
 
# Enable automatic security updates
$ sudo dpkg-reconfigure unattended-upgrades
 
# Or configure manually
$ sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Docker Base Image Updates

# Dockerfile pattern for keeping images updated
FROM ubuntu:22.04
 
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

Quick Reference

TaskAPT (Debian/Ubuntu)DNF (RHEL/Fedora)APK (Alpine)
Update package listapt updatednf check-updateapk update
Install packageapt install pkgdnf install pkgapk add pkg
Remove packageapt remove pkgdnf remove pkgapk del pkg
Update all packagesapt upgradednf updateapk upgrade
Search packagesapt search pkgdnf search pkgapk search pkg
Show package infoapt show pkgdnf info pkgapk info pkg
List installeddpkg -ldnf list --installedapk list --installed
Clean cacheapt cleandnf clean allapk cache clean

Practice Challenge

  1. Run apt update and see how many packages can be upgraded
  2. Use apt search to find a package related to your work (e.g., htop)
  3. Install htop (or bpytop) using your system's package manager
  4. Run the installed program and confirm it works
  5. Remove the package you just installed
  6. Use apt show to see details about the curl package — what dependencies does it have?