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.
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.
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.
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
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 pkgavoids storing the index, which keeps the layer small. It replaces theapt-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-r0installs an exact version if the repository still has it. - Package names differ from Debian: development headers are
-dev(as in Debian), documentation is-doc, andlibcdevelopment files come frommusl-dev. - The shell is BusyBox
ash, and many tools (ps,grep,sed,tar) are BusyBox applets with fewer options than the GNU versions. Addcoreutilsorgreppackages when a script needs GNU behavior. - Compared with
apt:apk addisapt install,apk delisapt remove,apk info -Wisdpkg -S.
Related
apt,pacman,dnf and yum- Lessons: Packages and services, Containers from scratch