# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/

<!-- PROSE:intro -->
`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.
<!-- PROSE:intro:end -->

## Update & Upgrade

`apk update` — Update the package index.

```bash
apk update
```

`apk upgrade` — Upgrade all installed packages.

```bash
apk upgrade
```

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

```bash
apk update && apk upgrade
```

## Install & Remove

`apk add <package>` — Install a package.

```bash
apk add curl
```

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

```bash
apk add curl wget git
```

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

```bash
apk add --no-cache nodejs npm
```

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

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

`apk del <package>` — Remove a package.

```bash
apk del nginx
```

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

```bash
apk del .build-deps
```

## Search & Info

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

```bash
apk search nginx
```

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

```bash
apk search -d 'web server'
```

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

```bash
apk info nginx
```

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

```bash
apk info -a nginx
```

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

```bash
apk info -L nginx
```

`apk list --installed` — List all installed packages.

```bash
apk list --installed
```

## Cache & Repositories

`apk cache clean` — Clean the package cache.

```bash
apk cache clean
```

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

```bash
cat /etc/apk/repositories
```

`apk add --repository <url> <package>` — Install from a specific repository.

```bash
apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing <package>
```

`apk policy <package>` — Show available versions and their repositories.

```bash
apk policy nodejs
```

## Docker Patterns

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

```bash
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).

```bash
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.

```bash
RUN apk --no-cache add curl bash
```

<!-- PROSE:outro -->
## 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](https://wiki.alpinelinux.org/wiki/Package_management) – official apk documentation
- [Alpine Linux – project site](https://alpinelinux.org/) – downloads, releases and background on the distribution
<!-- PROSE:outro:end -->

## Related Commands

- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – high-level package manager for Debian and Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – classic Debian/Ubuntu tool for scripts
- [brew](https://www.jpkc.com/db/en/cheatsheets/package-managers/brew/) – package manager for macOS and Linux

