Skip to content
Latchkey

apk Command Reference: Flags, Usage & CI Examples

apk is the package manager for Alpine Linux.

apk installs and removes packages on Alpine, the small base image common to slim CI containers. Its --no-cache and --virtual options keep image layers lean.

Common flags and usage

  • add <pkg...>: install packages
  • --no-cache: do not write an index cache (no cleanup needed)
  • --virtual <name> <pkg...>: group packages under a label
  • del <pkg/name>: remove packages or a virtual group
  • update / upgrade: refresh and upgrade the system
  • info -W <path>: find which package owns a file

Example

shell
apk add --no-cache ca-certificates postgresql-client
apk add --no-cache --virtual .build-deps gcc musl-dev make
# ... build ...
apk del .build-deps

In CI

Use apk add --no-cache so you do not need a separate cache-clean step. Group transient build tools under a --virtual label, then apk del that label after building to drop them from the final layer.

Key takeaways

  • apk add --no-cache installs without leaving an index cache.
  • --virtual groups build deps so apk del removes them in one step.
  • apk is the small-image package manager on Alpine.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →