apk is Alpine's package manager — short for "Alpine Package Keeper." Tiny, fast, and the right tool to know if you ever build a Dockerfile that starts with FROM alpine.
Prerequisites
- Alpine Linux 3.x with
sudoor root.
Step 1: Sync and upgrade
apk update # refresh index
apk upgrade # upgrade everything
apk upgrade -a # also handle replaces/swaps
Step 2: Install, remove, search
apk add nginx curl htop
apk del unused-pkg
apk search redis
apk info redis # what is installed
apk info -L nginx | head # files owned by nginx
apk info --who-owns /etc/nginx/nginx.conf
apk info -v | head # everything installed with version
Step 3: Repository tags
Alpine ships main (core, supported) and community (everything else). Edit /etc/apk/repositories:
https://dl-cdn.alpinelinux.org/alpine/v3.20/main
https://dl-cdn.alpinelinux.org/alpine/v3.20/community
# Edge — bleeding edge, do not mix with stable
# https://dl-cdn.alpinelinux.org/alpine/edge/main
# https://dl-cdn.alpinelinux.org/alpine/edge/community
# https://dl-cdn.alpinelinux.org/alpine/edge/testing
After editing, apk update.
To pull a single package from edge without switching the whole system:
apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community new-package
Step 4: Virtual packages — group installs/removes
apk add --virtual .build-deps gcc musl-dev make
# ... build something ...
apk del .build-deps
This is the standard Dockerfile pattern — install build dependencies as one virtual package, then delete the whole group after building.
Step 5: Holds and policy
apk version # what is installed vs available
apk version -l '<' # only show installs that are behind
apk hold nginx # pin nginx so upgrades skip it
apk unhold nginx
apk policy nginx # which repo a package would come from
Step 6: Local cache and clean
apk cache clean
apk cache --purge
apk audit # list locally modified config files
For Docker images especially:
apk add --no-cache curl # skip the local index cache entirely
--no-cache is the right flag in containers — it saves ~5 MB per image layer.
Verify
apk stats
apk verify
apk dot --installed | head # dependency graph (graphviz format)
Conclusion
apk's surface area is small on purpose. apk add, apk del, apk update && apk upgrade, and --virtual for build deps — that is the full daily toolkit.
Next steps
- Install Alpine first via 5-minute install.
- See Alpine in Docker for the container patterns.
- For glibc distros see Debian Nginx.
Comments
0 total · 0 threads