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 update

apk upgrade — Upgrade all installed packages.

apk upgrade

apk update && apk upgrade — Update index and upgrade packages in one step.

apk update && apk upgrade

Install & Remove

apk add <package> — Install a package.

apk add curl

apk add <pkg1> <pkg2> — Install multiple packages.

apk add curl wget git

apk add --no-cache <package> — Install without caching (smaller Docker images).

apk add --no-cache nodejs npm

apk add --virtual .<name> <packages> — Install as a virtual package (easy bulk removal later).

apk add --virtual .build-deps gcc musl-dev

apk del <package> — Remove a package.

apk del nginx

apk del .<name> — Remove a virtual package and all its members.

apk del .build-deps

Search & Info

apk search <query> — Search for packages by name.

apk search nginx

apk search -d '<query>' — Search in package descriptions.

apk search -d 'web server'

apk info <package> — Show info about an installed package.

apk info nginx

apk info -a <package> — Show all info (deps, size, files).

apk info -a nginx

apk info -L <package> — List files installed by a package.

apk info -L nginx

apk list --installed — List all installed packages.

apk list --installed

Cache & Repositories

apk cache clean — Clean the package cache.

apk cache clean

cat /etc/apk/repositories — Show configured repositories.

cat /etc/apk/repositories

apk 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 nodejs

Docker Patterns

apk add --no-cache <packages> — Standard Docker install pattern (no leftover cache).

RUN apk add --no-cache python3 py3-pip

apk 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-deps

apk --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

  • apt – high-level package manager for Debian and Ubuntu
  • apt-get – classic Debian/Ubuntu tool for scripts
  • brew – package manager for macOS and Linux