apk — The Alpine Linux Package Manager
Practical guide to apk: install, update and manage packages on Alpine Linux — lightweight, fast and the standard pattern for Docker images.
apk (Alpine Package Keeper) is the package manager of Alpine Linux – a deliberately minimal distribution you most likely know from lean Docker images. It installs, updates and removes packages quickly and with a tiny footprint, which makes it the default choice for containers. The key container pattern: apk add --no-cache installs packages without leaving the package index on disk, keeping your images small. This guide walks you through the commands you reach for most in day-to-day work and in Dockerfiles.
Update & Upgrade
apk update — Update the package index.
apk updateapk upgrade — Upgrade all installed packages.
apk upgradeapk update && apk upgrade — Update index and upgrade packages in one step.
apk update && apk upgradeInstall & Remove
apk add <package> — Install a package.
apk add curlapk add <pkg1> <pkg2> — Install multiple packages.
apk add curl wget gitapk add --no-cache <package> — Install without caching (smaller Docker images).
apk add --no-cache nodejs npmapk add --virtual .<name> <packages> — Install as a virtual package (easy bulk removal later).
apk add --virtual .build-deps gcc musl-devapk del <package> — Remove a package.
apk del nginxapk del .<name> — Remove a virtual package and all its members.
apk del .build-depsSearch & Info
apk search <query> — Search for packages by name.
apk search nginxapk search -d '<query>' — Search in package descriptions.
apk search -d 'web server'apk info <package> — Show info about an installed package.
apk info nginxapk info -a <package> — Show all info (deps, size, files).
apk info -a nginxapk info -L <package> — List files installed by a package.
apk info -L nginxapk list --installed — List all installed packages.
apk list --installedCache & Repositories
apk cache clean — Clean the package cache.
apk cache cleancat /etc/apk/repositories — Show configured repositories.
cat /etc/apk/repositoriesapk add --repository <url> <package> — Install from a specific repository.
apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing <package>apk policy <package> — Show available versions and their repositories.
apk policy nodejsDocker Patterns
apk add --no-cache <packages> — Standard Docker install pattern (no leftover cache).
RUN apk add --no-cache python3 py3-pipapk add --virtual .deps <pkgs> && ... && apk del .deps — Install build deps, compile, then remove (multi-stage alternative).
RUN apk add --virtual .build-deps gcc musl-dev && pip install package && apk del .build-depsapk --no-cache add <package> — Alternative syntax for no-cache install.
RUN apk --no-cache add curl bash Conclusion
apk makes package management on Alpine Linux fast and uncomplicated – exactly what you want in container environments. In Dockerfiles, apk add --no-cache is the standard: it avoids a leftover package index and keeps your images lean, with no follow-up apk cache clean needed. Keep in mind that apk del actually removes packages and that system-wide changes usually require root (or sudo) – a mistyped del command can drag dependencies along with it. Also install only from trusted repositories and with Alpine's official signing keys, especially when you point --repository at edge/testing.
Further Reading
- Alpine Linux Wiki: Package Management – official apk documentation
- Alpine Linux – project site – downloads, releases and background on the distribution