13 Apk Commands for Alpine Linux Package Management

Alpine Linux is an independent, free, and open-source Linux distribution based on BusyBox and musl. It is a lightweight and security-oriented Linux distribution that comes in a small footprint (about 160 MB).

For this reason, it’s widely used in creating containers that are lightweight and standalone units that provide an isolated environment to deploy and run applications.

Alpine Linux targets users who desire simplicity, security, and efficient resource utilization. It is designed for x86, x86-64. AArch64 and ARM architectures.

Like any other Linux distribution, Alpine Linux comes with its own package manager known as apk (Alpine Package Keeper) and comes pre-installed on all Alpine Linux distributions.

Apk handles all the package management operations including searching, installing, upgrading, listing, and removing software packages just to mention a few. In this guide, we showcase commonly used Apk command examples in Alpine Linux.

Alpine Linux Packages and Repositories

Before we look at the various apk commands that you can leverage to manage your packages, let us touch on Alpine Linux repositories.

Alpine Linux has two repositories enabled by default: the main and community repositories.

  1. The main repository comprises packages that are rigorously tested and approved to be officially hosted by the Alpine Linux core development team.
  2. The community repository, on the other hand, comprises community-supported packages which are ported from the edge or testing repositories.

On your local Alpine Linux system, you can find the repositories in the /etc/apk/repositories file, you can use the cat command to view them as follows.

$ cat /etc/apk/repositories 
Alpine Linux Repositories
Alpine Linux Repositories

Having looked at the repositories, let us straight away jump into managing packages using the apk package manager.

1. Update Alpine Linux

To update the repositories and package lists on Alpine Linux, run the command

$ apk update
Alpine Linux Update
Alpine Linux Update

2. Search for an Availability of Packages

Before installing packages, it’s worthwhile to check if the packages have been officially been hosted in the repositories. To do so, use the syntax:

$ apk search package_name   

For example, to search for a nano package in the repositories, run the command:

$ apk search nano
Search Package in Alpine Linux
Search Package in Alpine Linux

3. Get a Description of an Installed Package

To get a description of a package in the repositories, about the package pass the -v and -d flags as shown. The option -d is short for description whilst the -v option prints out verbose output.

$ apk search -v -d nano
Get Package Description in Alpine Linux
Get Package Description in Alpine Linux

4. Install Packages in Alpine Linux

To install packages on Alpine Linux, use the syntax:

$ apk add package_name

For example, to install the nano text editor, run the command:

$ apk add nano
Install Packages in Alpine Linux
Install Packages in Alpine Linux

Additionally, you can install multiple packages in a single command using the syntax:

$ apk add package1 package2

For example, the command below installs neofetch and vim editor at a go.

$ apk add neofetch vim
Install Multiple Packages in Alpine Linux
Install Multiple Packages in Alpine Linux

You can confirm if you installed neofetch by running the command:

$ neofetch

This populates information about the operating system such as OS type, kernel, uptime, and underlying hardware such as CPU and memory.

Neofetch Show Linux Information
Neofetch Show Linux Information

To confirm that vim editor is installed, simply run the vim command without any arguments and this will display information about vim.

$ vim
Vim Editor Info
Vim Editor Info

The -i option prompts for user interaction when installing packages. It causes apk to ask you whether to continue with the installation of the package or abort.

$ apk -i add apache2
Install Package Confirmation
Install Package Confirmation

5. Check Installed Package in Alpine Linux

To probe if a certain package is already installed, use the syntax:

$ apk -e info package_name

In this example, we are checking if Nano is installed.

$ apk -e info nano

In addition, you can check if multiple packages exist by listing them in the same line. For this example, we are verifying if both nano and vim are installed.

$ apk -e info nano vim
Check Package in Alpine Linux
Check Package in Alpine Linux

To list additional information such as the version and size of the installed package simply run:

$ apk info nano
Check Package Information in Alpine Linux
Check Package Information in Alpine Linux

6. List Files Associated with a Package

The -L flag allows you to list the files associated with a package, which includes the binary and configuration files and other files.

$ apk -L info nano
List Installed Package Files in Alpine Linux
List Installed Package Files in Alpine Linux

7. List Dependencies of a Package

With the -R option, you can list the packages that the package depends on. In the following example, we are listing the dependencies that vim depends on.

$ apk -R info vim
List Package Dependencies in Alpine Linux
List Package Dependencies in Alpine Linux

8. Find the Installed Size of a Package

To view the installed size of a package, use the -s option (lowercase) as follows:

$ apk -s info vim
Find Installed Package Size in Alpine Linux
Find Installed Package Size in Alpine Linux

9. List All Installed Packages

To list all installed packages on Alpine Linux, run the command:

$ apk info
List All Installed Packages in Alpine Linux
List All Installed Packages in Alpine Linux

10. Upgrade Alpine Linux

To upgrade all the packages on Alpine Linux to their latest versions, run the command

$ apk upgrade
Upgrade Alpine Linux
Upgrade Alpine Linux

To perform a dry run of the upgrade, pass the -s option. This merely runs a simulation and shows the versions that the packages will be upgraded to. It does not upgrade the packages.

$ apk -s upgrade
Dry Run Alpine Linux Upgrade
Dry Run Alpine Linux Upgrade

11. Hold a Package Upgrade

There are instances where you may want to keep a few packages back from an upgrade. For instance to keep nano in its current version – nano-5.9-r0 – run the command.

$ apk add nano=5.9-r0 
Hold Package Upgrade in Alpine Linux
Hold Package Upgrade in Alpine Linux

This will exempt the nano package from the upgrade as other packages are upgraded to their latest versions.

To later release the package for the upgrade, run:

$ apk add 'nano>5.9'

12. Remove a Package in Alpine Linux

If you no longer require a package, you can remove it using the syntax:

$ apk del package_name

For example, to delete vim, run the command.

$ apk del vim
Remove Packages in Alpine Linux
Remove Packages in Alpine Linux

13. Getting Help with Apk Command

For additional apk commands, you can browse the apk help catalog as shown

$ apk --help
Apk Command Help
Apk Command Help

In this guide, we focussed on Alpine apk command examples. We hope that this will help you as you get started installing and managing packages on Alpine Linux.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 Comments

Leave a Reply
  1. Why apk and not apt?
    Why apk add and not apk install?

    I wish I could get rid of this strange distro from my docker containers.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.