- How to Install / Remove packages on Alpine Linux
- Steps to delete / Remove a package from Alpine linux Server
- Working with the Alpine Package Keeper ( apk )
- Normal Usage
- Repositories, Releases and Mirrors
- Searching for Packages
- Installing Packages
- Upgrading Packages
- Querying Package Information
- Removing Packages
- Cleanup
- Advanced Usage
- World
- Virtuals
- Swapping Repositories
- Alpine Linux Apk Command Examples
- A brief introduction to apk package manager
- Apk command examples to install and manage packages in Alpine Linux
- 1. Display apk command help
- 2. Update package list in Alpine Linux
- 3. Install packages in Alpine Linux
- 3.1. Install local packages
- 4. Remove packages in Alpine Linux
- 5. Search packages in Alpine Linux
- 6. Display package details in Alpine Linux
- 7. List installed packages in Alpine Linux
- 8. Upgrade packages in Alpine Linux
- 9. Upgrade Alpine Linux
- 10. Hold a package from upgrade
- 11. Download packages in Alpine Linux
- 12. Display repository details of a package
- 13. Show statistics of packages and repositories
- 14. Clean package cache
How to Install / Remove packages on Alpine Linux
Use ‘apk add [package_name]’ command to install package on Alpine Linux Server.
‘apk delete [package_name]’ command will delete the package from the server.
1. Log into Alpine Linux server as ‘root’ user
2. Run the command ‘apk add [package]’ to install package on the server
Example : apk add supervisor
You can add “—interactive” option with ‘apk add’ command to ask for confirmation before installing the package.
apk add [package_name] —interactive
The following NEW packages will be installed:
After this operation, 47 MiB of additional disk space will be used.
Do you want to continue [Y/n]?
Installation will proceed only after getting confirmation from your end.
Use “—no-cache” option if you do not want to use local cache path.
# apk add [package_name] —no-cache
If you want to print less information while installing a package then use ‘—quiet’ option with apk add.
# apk add [package_name] —quiet
Steps to delete / Remove a package from Alpine linux Server
2. Execute the command ‘apk del [package_name]’ to delete the package
# apk del supervisor
To print less information while deleting use the ‘—quiet’ option.
# apk del supervisor —quiet
If you use “—interactive” option, apk add will ask for confirmation before deleting the package.
# apk del [package_name] —interactive
The following packages will be REMOVED:
After this operation, 47 MiB of disk space will be freed.
Do you want to continue [Y/n]?
Working with the Alpine Package Keeper ( apk )
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-tools package.
Normal Usage
Repositories, Releases and Mirrors
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.
Packages from testing that have been tested.
New, broken, or outdated packages that need testing. Only available on edge .
Two types of releases exist:
Released every 6 months. Support entails security patches for the given feature versions. Each stable release has its own main and community repositories. The main repository is supported for 2 years. The community repository is only supported for 6 months of its respective release. A release is considered EOL (End Of Life) when support of its main repo expires.
A rolling release branch. It includes newest packages built from the master branch of the aports repository. It’s less stable than release branches, but is stable enough for daily use and is useful for development or if you need up to date software. It has its own main and community repos, just like stable releases. It also has the testing repository, which increases the number of available packages significantly.
It is technically possible to mix different branches, that is to say to enable the testing repository while using main and community from stable. However, this approach is discouraged and will cause breakages. |
Repositories are configurable in the /etc/apk/repositories file. Each line corresponds to a repository. The format is as follows:
In this case, http:// is the protocol, dl-cdn.alpinelinux.org/alpine is the path, edge is the release and main is the repository. |
In this case, @testing is the tag. More on this in Installing Packages. |
In this case, the repository is a personal one, available on the filesystem of the machine. |
This example uses the http:// protocol. ftp:// and https:// protocols are also supported. |
This file should already have been been partially populated when you installed alpine. |
Searching for Packages
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. However, 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:
You can search for partial library names. |
You can also search for binary names. |
You can exclude partial matches using -e . |
You can specify that what you’re searching for is a library using the so: prefix (or the cmd: prefix for commands, and pc: prefix for pkg-config files) — it will work with -e (in fact, the prefix is required for this use-case if -e is used). |
Installing Packages
Once you know what package you want to install, you must know how to do that. Apk’s add command is more strict than the search command — wildcards are not available, for instance. However, the cmd: , so: and pc: prefixes are still available.
While the so: prefix is still available for apk add , it is recommended that you avoid using it. This is because the provided library SONAME version can increase (for example, libmpack.so.0 may get updated, and become libmpack.so.1 ), in which case this will not update libmpack next time you run apk upgrade , and will instead fail. This is because so:libmpack.so.0 directly refers to that specific version of the library, and is typically used by packages, rather than users directly.
While the cmd: and pc: prefix is still available for apk add , you should know that it does not guarantee getting you the exact package you are looking for. Multiple packages can contain the same executable command or pkg-config definition, but only one will be selected — not necessarily the one you want.
Here are a few examples of adding packages:
You must specify the exact package name. |
You may add multiple packages at once. |
This should be equivalent to the previous example, but specifies the command you are interested in. |
It is possible, but discouraged, to specify specific desired libraries. |
Finally, it is possible to specify pkg-config dependencies. |
If apk add finds multiple matching packages (for example multiple cmd: matches), it will select the one with the highest version number. |
Upgrading Packages
Updating the system using apk is very simple. One need only run apk upgrade . 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 /etc directory. Whenever apk wants to install a file, but realizes a potentially edited one is already present, it will write its file to that filename with .apk-new appended. You may handle these by hand, but a utility called update-conf exists. Simply invoking it normally with present you with the difference between the two files, and offer various choices for dealing with the conflicts.
apk update is only ran once your cache is invalidated, which by default happens every 4 hours. |
Querying Package Information
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. By default, 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.
Removing Packages
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 add subcommand.
If you added a package using the cmd: , so: or pc: virtual, you must specify the same virtual to remove them. NOTE: Removing a package will automatically remove all of its dependencies that are otherwise not used. |
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.
Cleanup
Many package managers have specific features to «clean up». A common one is apt , which has an autoremove subcommand. Apk does this by default when removing packages.
It is also possible to clear out the apk cache, assuming it is enabled. You can do this using apk cache clean .
Advanced Usage
World
The packages you want to have explicitly installed are listed in the «world file», available in /etc/apk/world . 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.
Virtuals like cmd: , so: and pc: will appear as such in your world file — this is why using so: is discouraged — the soname might get bumped! |
Virtuals
While cmd: , so: and 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:
This will add the packages «a», «b» and «c» as the dependencies of a virtual package «abc». |
This will remove «abc» and all of its components («a», «b» and «c»), unless they are required elsewhere. |
This is equivalent to the first example. |
Swapping Repositories
When alpine has a new release, the repository path will change. Assuming you are going forward in time (e.g from 3.12 to 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.
Copyright © 2019 Alpine Linux Development Team. All rights reserved.
Alpine Linux Apk Command Examples
This guide explains what is Apk package manager and how to do various Alpine Linux package management operations using Apk command line package manager with examples.
A brief introduction to apk package manager
Apk, stands for Alpine Package Keeper, is the default package manager for Alpine Linux. It is used to install, update, upgrade, search, list and remove packages on a running Alpine Linux system. Apk is the part of apk-tools package which comes pre-installed in all Alpine Linux versions.
Apk retrieves packages as well as information about available packages in the online repositories. Each repository contains a special index file, named APKINDEX.tar.gz . All software packages stored in a repository are digitally signed tar.gz archives. They have the extension .apk , and are often called «a-packs».
Starting from Alpine Linux version 3.3, there are two repositories enabled by default. They are — main and community .
The [main] repository consists of the packages that are thoroughly tested and officially supported by Alpine Linux core team. The [community] repository contains the community supported packages which are accepted from the [testing] or [edge] repository. The [testing] repository usually have the new, broken and/or outdated packages. No support is provided for this repository and it is not included in the release snapshots.
All repositories are configured in /etc/apk/repositories file. Let us take a look at the contents of this file using cat command:
Sample output:
Each line in the above file indicates a repository. As you can see in the above output, I have enabled [edge] repository, so it is rolling release version.
If you are using stable release, you should have seen the version number, for example v3.12 , like below:
Apk command examples to install and manage packages in Alpine Linux
Package management using apk in Alpine Linux is quite simple and straight forward. Apk doesn’t include much options and the syntax is easier to remember.
The typical usage of apk package manager is:
Let me show you a few important commands for day-today operations.
1. Display apk command help
If you are new to apk, you can view the apk command help section at any time by running this command:
apk has many sub-commands to perform a specific operation. To display the help section of a sub-command, run:
2. Update package list in Alpine Linux
To get the list of available packages in Alpine Linux repositories, simply run:
Sample output:
As you can see in the above output, currently there are 13780 packages available in Alpine repositories. Please note that these are not the total number of locally installed packages but the total number of available packages.
3. Install packages in Alpine Linux
To add or install a package, for example vim, in Alpine Linux, simply run:
The above command will install vim and its dependencies.
Similarly, you can add multiple packages by mentioning them with a space like below:
3.1. Install local packages
If you already have downloaded a package, you can then install it like below.
You can also install multiple packages as well:
4. Remove packages in Alpine Linux
To uninstall or remove an installed package from your Alpine Linux system, run:
This command will remove vim and its dependencies.
If you want to delete multiple packages, mention them with space-separated.
5. Search packages in Alpine Linux
Alpine Linux repositories contains more than 13,000 packages. You can list all available packages, along with their description, using command:
Sample output:
To display only the total number of packages, pipe the output to wc command like below:
You can also get the list of all packages matching a pattern. For example, the following command will display all packages that matches the search term «vim».
If you only want to display the packages that contains a specific term in their description, run:
Or, shortly use -d switch:
6. Display package details in Alpine Linux
To display the details of a specific package, we can use info command like below:
You will see the small description of the given package and it’s website where it is hosted.
Sample output:
As you can see, this command not only lists the vim package details but also the other packages’ details that contains the pattern «vim» in their name.
If you want the detailed information about the given package and its dependencies, use -a flag.
The above command will display the following details:
- package description.
- website of the package.
- installed size (i.e. the size required by the package after it is installed).
- the contents of the package (i.e. list of files that the package installs).
- package dependencies i.e. what packages are required to use this one.
- what packages require this one to be installed.
- and more.
7. List installed packages in Alpine Linux
To view list of all installed packages in your Alpine Linux system, run:
Sample output:
You can also list the installed packages with their version number and description:
Sample output:
List only total number of installed packages:
8. Upgrade packages in Alpine Linux
To upgrade a specific package, run:
To upgrade all installed packages, run:
You can also combine the above command into one like below:
9. Upgrade Alpine Linux
Upgrading a running Alpine Linux to next available version is easy! Alpine Linux comes in two editions:
You can either upgrade from current stable version to newer version or convert a stable version into a rolling release version.
More detailed instructions are available in the following guide:
10. Hold a package from upgrade
Sometimes, you want to prevent or hold a package from being automatically upgraded for some reason when upgrading your Alpine Linux system. There could be many reasons to hold a package back. For instance, a particular version is required by an application in order to work properly. Or the new package may break your system. So you want to ignore the packages from being upgraded when you upgrade the system.
To hold a specific package from upgrade, use any one of the following commands:
And then, do the system upgrade using command:
This command will upgrade all packages but keep the vim package at 8.2.0 or lower version.
You can later upgrade vim package to currently available version like below:
You can also use «fuzzy» version matching to pin the version to a major/minor release. For instance, the following command will match any version of vim that starts with 8.2.
Related read:
11. Download packages in Alpine Linux
Sometimes, you want to download a specific package but don’t want to install it. For instance, let us download vim package using command:
The above command will display the vim package from Alpine repositories and save it in the current directory.
If you want to save the package in different path, use -o switch.
Please note that this command will not download all required dependencies but only the actual package.
To download the given package along with all required dependencies, use -R ( —recursive ) flag:
Sample output:
You can install the locally downloaded packages as shown in 3.1. Install local packages section.
12. Display repository details of a package
You might want to find which repository a package comes from. Apk has a sub-command for that too.
To display the repository a package (E.g. vim ) was installed from and will be updated from, use apk policy command:
Sample output:
As you can see, vim package has been installed from the [main] repository.
13. Show statistics of packages and repositories
We can print the statistics about installed packages and package repositories using command:
Sample output:
14. Clean package cache
By default, all installed packages are cached in /etc/apk/cache/ directory. When newer packages are added to the cache, the older versions of the packages remains by default.
If you don’t want the older versions of the packages, you can simply clear the package cache using command:
If you want to see what versions are deleted, use -v (verbose) switch:
If you have accidentally delete packages from the cache, you can download them using command:
You can also delete the cache and download the missing package in a single command: