Package management

Package Managers

  • apt (Debian Family)
  • dnf (Red Hat Family)
  • pacman (Arch Family)
  • zypper (SUSE Family)
  • emerge (Gentoo Family)
  • apk (Alpine Linux)
  • nix (NixOS)

High Level vs Low Level package tools

  • High level tools handle metadata searching and dependency resolution
  • Low level tools handle installing and removing packages
  • Debian Family
    • High level: apt, apt-get, aptitude
    • Low level: dpkg
  • Red Hat Family
    • High Level: dnf, yum
    • Low level: rpm

Universal Package Managers

  • work across distros by bundling their own dependencies, independent of the host’s native package manager
  • snap
    • by Canonical
    • sandboxed
  • flatpak
    • by Red Hat
    • sandboxed

apt

  • apt-get is the older, stable, scriptable CLI - safe to use in scripts
  • apt is the newer high-level CLI meant for interactive use
  • apt adds: progress bars, color output, combined apt search, apt list
  • both call the same underlying libraries; no functional difference for common tasks
# refresh package index from all configured repos
apt update
 
# upgrade all installed packages to latest versions
apt upgrade
 
# like upgrade, but also removes packages if needed to resolve deps
apt full-upgrade
 
# install a package
apt install <package>
 
# install a local package
apt install <file>.deb
 
# remove package but keep config files
apt remove <package>
 
# remove package AND its config files
apt purge <package>
 
# remove orphaned dependencies no longer needed
apt autoremove
 
# search package names and descriptions
apt search <term>
 
# show metadata: version, deps, description
apt show <package>
 
# list all installed packages
apt list --installed

dpkg

  • low-level package tool that apt is built on top of
  • apt resolves dependencies then hands off to dpkg to do the actual install
  • works directly with .deb files on disk (no network, no repo)
# install a local .deb file
dpkg -i <file>.deb
 
# remove a package (keeps config)
dpkg -r <package>
 
# remove a package AND its config files
dpkg --purge <package>
 
# list all installed packages
dpkg -l
 
# check if a package is installed
dpkg -s <package>
 
# list files installed by a package
dpkg -L <package>
 
# find which package owns a file
dpkg -S /usr/bin/curl
  • dpkg -i do not have internet access and cannot do dependency resolution if the dependencies are missing
  • It is recommended to run apt install instead of dpkg -i for installing local debian files
  • If dpkg -i fails to install dependencies
    • the package gets into broken state
    • running apt install -f installs the missing dependencies

Repository management

  • /etc/apt/sources.list: main repo config file
  • /etc/apt/sources.list.d/: drop-in directory; one .list file per repo
# deb <url> <codename> <components...>
deb https://deb.debian.org/debian bookworm main contrib non-free
  • components: buckets within a repo that separate packages by licensing and support policy
    • main: officially supported, open-source
    • contrib: open-source but depends on non-free packages
    • non-free / non-free-firmware: proprietary
    • Ubuntu adds its own:
      • universe: community-maintained open-source, not officially supported
      • restricted: proprietary drivers Canonical supports
      • multiverse: non-free, unsupported

Personal Package Archive

  • aka PPA
  • Third-party repos hosted on Launchpad (Ubuntu only)
# add a PPA
add-apt-repository ppa:<user>/<repo>
 
# remove a PPA
add-apt-repository --remove ppa:<user>/<repo>
 
# list all configured repos
apt-cache policy
 
# list files in /etc/apt/sources.list.d/
ls /etc/apt/sources.list.d/

Package Naming Conventions

  • Prefixes
    • lib*: shared libraries
      • example: libcurl4, libxml2
    • python3-* / golang-* / ruby-*: language-specific modules
    • firmware-*: hardware drivers (usually proprietary)
      • example: firmware-iwlwifi
  • Suffixes
    • -dev: development headers and static libs for compiling against a library
      • example: libssl-dev
    • -common: arch-independent shared files used across related packages
      • example: mysql-common
    • -data: assets (graphics, audio, translations)
      • example: vlc-data
    • -doc: manuals and guides
      • example: git-doc
    • -utils / -tools: command-line helper utilities
      • example: dnsutils
    • -server / -client: service role split
      • example: openssh-server, openssh-client
    • -plugin / -addon / -ext: optional feature extensions
      • example: gedit-plugins
    • -meta: virtual package with no code; pulls in a bundle of related packages as dependencies
      • example: build-essential
    • -dbg / -dbgsym: debugging symbols, used with tools like gdb
      • example: libc6-dbg