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-depsIn 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
apt-get Command Reference: Flags, Usage & CI ExamplesReference for apt-get: update, install, -y, DEBIAN_FRONTEND, --no-install-recommends, and a CI example that i…
dnf Command Reference: Flags, Usage & CI ExamplesReference for dnf: install, -y, --setopt=install_weak_deps, remove, clean all, and a CI example that installs…
brew Command Reference: Flags, Usage & CI ExamplesReference for Homebrew brew: install, --cask, bundle, HOMEBREW_NO_AUTO_UPDATE, and a CI example that installs…