Skip to content
Latchkey

apk add --no-cache: Install Packages on Alpine

apk add --no-cache installs packages on Alpine without leaving an index cache behind, ideal for small Docker images.

Alpine images are the default for slim containers, and apk is its package manager. The --no-cache flag is what keeps those images tiny.

What it does

apk add installs the named packages and their dependencies from the configured repositories. --no-cache fetches a fresh index for this command and does not write it to /var/cache/apk, so there is nothing to clean up afterward.

Common usage

Terminal
apk add --no-cache curl ca-certificates
# pin a version
apk add --no-cache "nodejs=~20"
# build deps in a removable virtual group
apk add --no-cache --virtual .build-deps gcc musl-dev make
# ... build ...
apk del .build-deps

Options

FlagWhat it does
--no-cacheDo not cache the index; keeps images small
--virtual <name>Group packages so apk del <name> removes them all
--repository <url>Add a repository just for this command
--no-progressSuppress the progress bar (cleaner logs)
-t / --virtualAlias for creating a virtual package group
pkg=versionInstall an exact version

In CI

Use --no-cache instead of the older apk update && apk add ... && rm -rf /var/cache/apk/* pattern; it is one flag and always correct. Wrap compile-time dependencies in --virtual .build-deps so a single apk del removes them before the final layer.

Common errors in CI

"ERROR: unable to select packages" with "so:libX.so.1 (no such package)" means a dependency is missing from the enabled repos, often the community or edge repo; enable it. "WARNING: Ignoring ... No such file or directory" for a repo means the mirror is unreachable. "ERROR: <pkg> (no such package)" means the name is wrong or absent in this Alpine version.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →