Learn Alpine Linux - Package Management with apk
Episode 4 of 23

Learn Alpine Linux - Package Management with apk

This episode takes a deep dive into apk, Alpine's package manager. You'll learn the basic apk update, add, del, and upgrade commands, the repository structure in /etc/apk/repositories, and apk search, info, and audit. The episode also explains the differences between apk v2 on older versions and apk v3 on Alpine 3.23 and later.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

Packages are how Alpine distributes software, and apk (Alpine Package Keeper) is the vehicle. Episode 4 covers apk thoroughly: basic commands, repository structure, querying and auditing, up to the differences between apk v2 and apk v3 introduced in Alpine 3.23.

Since apk is the tool you'll use in almost every episode, mastering it early will make the whole series much smoother. The goal isn't just to memorize commands, but to understand apk's working model so you can predict its behavior in new situations.

Basic apk Commands

update, add, del, and upgrade

The four most frequently used commands:

Package lifecycle with apk
apk update
apk add nginx
apk add --no-cache curl
apk del nginx
apk upgrade

Brief explanation:

  • apk update refreshes the package index from the repositories.
  • apk add installs a package together with its dependencies.
  • apk add --no-cache installs without keeping the index — required in Dockerfiles.
  • apk del removes a package.
  • apk upgrade upgrades all packages to the latest versions in the active repositories.

Installing packages with dependencies is handled automatically by apk's SAT solver, so you don't need to worry about choosing an order:

Install several packages at once
apk add vim git htop

One detail that sets apk apart from apt: after apk del nginx, packages that are no longer needed aren't automatically removed. Use apk fix when there are problematic dependencies:

Fix broken dependencies
apk fix

Repositories and /etc/apk/repositories

Three Repository Tiers

The /etc/apk/repositories file determines the active repositories, one line per repository:

Contents of /etc/apk/repositories
https://dl-cdn.alpinelinux.org/alpine/v3.24/main
https://dl-cdn.alpinelinux.org/alpine/v3.24/community
  • main contains the core packages supported by the Alpine team.
  • community contains community packages, stable enough for light production.
  • testing isn't listed by default and is only for testing.

To add the testing repository, append its line:

Enable the testing repository
echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
apk update

Don't forget to adjust the version number to match your release. Mixing different versions in a single repositories file can cause conflicts, so always use a single branch.

Querying Packages: search, info, and audit

Finding and Inspecting Packages

To find and inspect packages, apk provides query commands:

Query packages with apk
apk search nginx
apk search -d "web server" | head -10
apk info -e nginx
apk info -a nginx | head -20
apk info -W /usr/bin/nginx

Explanation:

  • apk search finds packages by name or description.
  • apk info -e checks whether a package is installed.
  • apk info -a shows a package's full metadata.
  • apk info -W finds the owner of a file.

apk audit for Integrity

apk audit compares the filesystem against the package database to detect changed or missing files:

Audit filesystem integrity
apk audit
apk audit --system

The apk audit output shows files that were added or changed from their post-install state. In episode 13, this command becomes one of the security hardening tools for detecting suspiciously modified files.

apk v2 versus apk v3

Changes in Alpine 3.23

Alpine 3.23 (December 2025) introduced apk v3, a major release with a new archive and index format. The differences you need to know:

  • Speed: index parsing and dependency resolution are much faster.
  • Format: the index uses a new, more compact format; the package format stays compatible.
  • Features: better support for caching, configuration, and modern tooling integration.
  • Migration: fresh installs use apk v3 right away; upgrades from older versions happen transparently.

Check the running apk version:

Check the apk version
apk --version
apk version

The apk --version output shows a number like apk-tools 3.0.0-r1 on Alpine 3.24, or apk-tools 2.14.x on releases before 3.23. The everyday command syntax hasn't changed, so your knowledge stays valid across versions.

Info

Never mix packages from different branches, for example v3.24 with edge, on a single system. apk will resolve them technically, but this combination isn't supported and often breaks upgrades.

Closing

Episode 4 covered apk from the basic commands to the repository architecture: update, add, del, and upgrade for the package lifecycle; main, community, and testing as repository tiers; search, info, and audit for querying; and the differences between apk v2 and apk v3.

Key takeaways:

  • apk update, apk add, apk del, and apk upgrade are the basic package lifecycle.
  • apk add --no-cache is important for minimal container images.
  • /etc/apk/repositories holds main and community; testing is only for trials.
  • apk search, apk info, and apk audit are the query and integrity tools.
  • apk v3 speeds up dependency resolution since Alpine 3.23.
  • Don't mix different repository branches on a single system.

In the next episode, episode 5, we'll discuss OpenRC: init system and service management — how Alpine boots without systemd, managing services with rc-service and rc-update, reading rc-status, and writing init scripts and configuration in /etc/conf.d.