Working with the Alpine Package Keeper (
apk is the Alpine Package Keeper - the distribution’s package manager.
It is used to manage the packages (software and otherwise) of the system.
It is the primary method for installing additional software, and is available in the
apk fetches information about available packages, as well as the packages themselves from various mirrors, which contain various repositories.
Sometimes, those terms are used interchangeably.
Here is a summary of relevant definitions:
A website that hosts repositories.
A collection of snapshots of various repositories.
A category of packages, tied together by some attribute.
Currently, three repositories exist:
Officially supported packages that are reasonable to expect to be in a basic system. Support cycles are 2 years long.
Packages from testing that have been tested. Support cycles are 6 months long.
New, broken, or outdated packages that need testing. No support for this repository is implied. It is not present in release snapshots.
Releases are versioned using a versioning scheme somewhat reminiscent of semantic versioning. However, one special release exists called "edge" - this is a "rolling" release. "Edge" is not officially supported - if you choose to run it, you are on your own. "Edge" is also the only release that contains the "testing" repository.
Repositories are configurable in the
Each line corresponds to a repository.
The format is as follows:
[@tag] [protocol][/path][/release]/repository # comments look like so. valid examples below http://dl-cdn.alpinelinux.org/alpine/edge/main (1) @testing http://dl-cdn.alpinelinux.org/alpine/edge/testing (2) /var/apk/my-packages (3)
|1||In this case,
|2||In this case,
|3||In this case, the repository is a personal one, available on the filesystem of the machine.|
This example uses the
|This file should already have been been partially populated when you installed alpine.|
In order to know what package to install, one must be able to find packages.
Alpine has a specialized web interface dedicated to looking through various available packages.
apk also provides a built-in searching mechanism.
You invoke it by using the
apk search subcommand.
You can potentially search for anything in the package index, which, among other things, includes provided binaries and libraries).
Further, globbing is supported.
As such, here are a few examples of searching:
apk search libsqlite3.so (1) apk search consul (2) apk search -e vim (3) apk search -e so:libsqlite3.so.* (4)
|1||You can search for partial library names.|
|2||You can also search for binary names.|
|3||You can exclude partial matches using
|4||You can specify that what you’re searching for is a library using the
Once you know what package you want to install, you must know how to do that.
add command is more strict than the
search command - wildcards are not available, for instance.
pc: prefixes are still available.
Here are a few examples of adding packages:
apk add busybox-extras (1) apk add bash zsh (2) apk add cmd:bash cmd:zsh (3) apk add so:libmpack.so.0 (4) apk add pc:msgpack (5)
|1||You must specify the exact package name.|
|2||You may add multiple packages at once.|
|3||This should be equivalent to the previous example, but specifies the command you are interested in.|
|4||It is possible, but discouraged, to specify specific desired libraries.|
|5||Finally, it is possible to specify pkg-config dependencies.|
Updating the system using apk is very simple.
One need only run
Technically, this is two steps:
apk update, followed by
apk upgrade proper.
The first step will download an updated package index from the repositories, while the second step will update all packages in World, as well as their dependencies.
apk will avoid overwriting files you may have changed.
These will usually be in the
apk wants to install a file, but realizes a potentially edited one is already present, it will write its file to that filename with
You may handle these by hand, but a utility called
Simply invoking it normally with present you with the difference between the two files, and offer various choices for dealing with the conflicts.
In some cases, it may be useful to inspect packages or files to see various details.
For this use, the
info subcommand exists.
It may be used on any package, installed or not, though the information on the latter will be more limited.
It may also be used with specific flags on files.
info will list the package description, webpage and installed size.
For more details (such as a list of flags the subcommand supports), you can use the
apk info -h output’s "Info options" section or see the manual page.
Often, it is desirable to remove a package.
This can be done using the
del subcommand, with a base syntax that is identical to the
If you added a package using the
del subcommand also supports the
-r flag, which will remove all packages that depend on the package being removed as well, rather than error out due to the package being needed.
The packages you want to have explicitly installed are listed in the "world file", available in
It is safe to edit it by hand.
If you’ve edited it by hand, you may run
apk add with no arguments to bring the package selection to a consistent state.
pc: packages are automatically created virtuals, you can create your own as well.
These allow for quick removal of purpose-specific packages.
See the following examples for details:
apk add a b c -t abc (1) apk del abc (2) apk add a b c --virtual abc (3)
|1||This will add the packages "a", "b" and "c" as the dependencies of a virtual package "abc".|
|2||This will remove "abc" and all of its components ("a", "b" and "c"), unless they are required elsewhere.|
|3||This is equivalent to the first example.|
When alpine has a new release, the repository path will change.
Assuming you are going forward in time (e.g from
3.13), you can simply edit
/etc/apk/repositories and run
apk upgrade --available.
Downgrading packages/versions is currently not supported. While it is technically possible, you are on your own.
|This is why it is not recommended to use edge repositories, unless you know what you’re doing, or are tagging all those packages.|