Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux apk command

Reference for apk, the Alpine Linux package manager: add, del, update, upgrade, search and info, virtual packages, and its use in small Docker images.

apk is the package manager of Alpine Linux, the small distribution built on musl libc and BusyBox that is popular as a base for container images. It is fast, has few moving parts and uses short verbs: add, del, update, upgrade, search, info.

The package index is kept in /var/cache/apk (or fetched on demand) and the list of repositories lives in /etc/apk/repositories. Because Alpine uses musl instead of glibc, binaries built for other distributions often do not run on it.

Terminal
apk update                     # fetch fresh package lists
apk add curl                   # install
apk add --no-cache curl        # install without keeping the index (Docker)
apk del curl                   # remove

Try it

The sandbox is Debian-based, so apk is not installed. These two examples are read-only: they parse a sample /etc/apk/repositories and sample apk info -v output.

Bash Repositories file (sample data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Splitting name and version (sample data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
apk [GLOBAL OPTIONS] COMMAND [OPTIONS] [ARGS]
Command Description
add pkg... Install packages (and dependencies). With -u also upgrade them.
del pkg... Remove packages. Dependencies that nothing else needs are removed too; --purge also deletes their config files.
update Download the repository indexes.
upgrade Upgrade all installed packages.
search word Search package names; -d searches descriptions, -v shows versions.
info [pkg] List installed packages, or show details of one. -L pkg lists files, -W file finds the owner of a file.
list List packages; --installed or -I limits to installed.
fix Repair or reinstall a package.
cache clean Remove old cached packages.
Option Description
--no-cache Do not use or keep the local index; fetch it for this command only.
-t NAME, --virtual NAME Group the packages added now under a virtual package for easy removal.
-U, --update-cache Update the index first.
-q, -v Quieter or more verbose output.

Returns: 0 on success; non-zero if a package is unknown, a dependency cannot be satisfied or the index cannot be fetched.

Usage notes

  • Docker images: apk add --no-cache pkg avoids storing the index, which keeps the layer small. It replaces the apt-get update && apt-get install && rm -rf /var/lib/apt/lists/* dance.
  • Build dependencies: install compilers under a virtual name and drop them in the same layer: apk add --no-cache --virtual .build-deps gcc musl-dev && ... && apk del .build-deps.
  • musl, not glibc: some prebuilt programs (many Python wheels, some Node addons, proprietary binaries) expect glibc and fail with "not found" or missing symbols. Compile from source or use a Debian-based image if that is a problem.
  • Pinning versions: apk add curl=8.11.1-r0 installs an exact version if the repository still has it.
  • Package names differ from Debian: development headers are -dev (as in Debian), documentation is -doc, and libc development files come from musl-dev.
  • The shell is BusyBox ash, and many tools (ps, grep, sed, tar) are BusyBox applets with fewer options than the GNU versions. Add coreutils or grep packages when a script needs GNU behavior.
  • Compared with apt: apk add is apt install, apk del is apt remove, apk info -W is dpkg -S.