Home Alpine Linux Getting Started with Alpine Linux Apk Command Examples

Getting Started with Alpine Linux Apk Command Examples

Every Linux distribution has its package manager that plays a role in the installation and management of software packages. For Debian/Ubuntu we have an apt package manager.

For RHEL and modern RedHat distributions such as CentOS, Rocky Linux, and AlmaLinux, the package manager is DNF. Of course, we have universal package managers such as snap and flatpak.

In Alpine Linux, APK, short for Alpine Package Keeper, is the package management tool. It retrieves packages and information about the packages from online repositories.

There are two main branches of these repositories:

  • Main repository
  • Community repository

The main repository contains packages that are directly supported and updated by the Alpine Linux core team. In addition, the packages also come with official documentation and are available for all Alpine Linux releases. Packages from the main repository will always have replacements if they do not go past upstream.

The Community repository includes community-supported packages, which are packages that have been passed from the testing repository where a team of independent users works in close collaboration with Alpine developers to develop packages.

On Alpine, these repositories are located in the /etc/apk/repositories file and you can view them using the cat command.

$ cat /etc/apk/repositories 


Now let us proceed and see how to manage packages on Alpine Linux using the apk package manager.

1. Update Alpine Linux Packages

It’s best practice to always refresh the local package lists before installing any software packages. To do this, run the command:

$ apk update
Update Alpine Linux
Update Alpine Linux

2. Search Packages on Alpine Linux Repository

There are thousands of software packages available in Alpine Linux repositories. To have a glance at all the packages, run the command

# apk search -v

The above command generates a long list of packages on the terminal and is not really helpful. Instead, you can search for a specific package that you are interested in.

For example, to search for all instances of nodejs, run the command

# apk search -v nodejs
# apk search -v | grep -i nodejs
Search Package in Alpine Linux
Search Package in Alpine Linux

3. Install Packages in Alpine Linux

To install a package on Alpine Linux, use the following syntax:

$ apk add package

For example, to install Python3, run the command:

$ apk add python3 
Install Package in Alpine Linux
Install Package in Alpine Linux

In addition, you can specify multiple packages to be installed in a single command as shown.

# apk add package1 package2

For example, to install Apache web server and MariaDB database server packages, run the command

# apk add apache2 mariadb
Install Packages in Alpine Linux
Install Packages in Alpine Linux

4. List Installed Software Packages

To list all the installed packages, run the apk info command:

# apk info
List Installed Packages in Alpine Linux
List Installed Packages in Alpine Linux

To check if a specific package is installed, use the syntax:

# apk info package-name

The command prints out the following:

  • The version of the package.
  • A brief description of the package.
  • The website of the parent company.
  • The installed size.

For example, to check if MariaDB is installed, run the command:

# apk info mariadb

To extract detailed information about a package, use the -a flag.

# apk info -a mariadb

With this information, you get additional information such as

  • Package dependencies.
  • The list of packages that the package contains.
  • The packages whose autoinstallation is likely to be affected.

5. Upgrade Packages in Alpine Linux

To upgrade all packages on Alpine Linux, run the following commands in succession:

# apk update
# apk upgrade

These commands can be combined into one as follows:

# apk -U upgrade
Upgrade Package in Alpine Linux
Upgrade Package in Alpine Linux

Also, might consider performing a dry run of the upgrade. This simulates the upgrade and shows you how the packages will be upgraded. You can achieve this using the -s option.

# apk -s upgrade

6. Exclude a Package from Being Upgraded

Sometimes, you might need to hold back a software package from being upgraded. The reasons for doing this are varied. For example, a new version of a package might be buggy and fraught with issues, and for that reason, you might want to continue using your current version which works smoothly with other applications.

To hold back a package from an upgrade in Alpine Linux, use the syntax shown.

# apk add package=version

In the example below, we are holding back MariaDB version 10.6.7-r0 from being upgraded.

# apk add mariadb=10.6.7-r0
Exclude Package from Upgrade in Alpine Linux
Exclude Package from Upgrade in Alpine Linux

With that, you can now upgrade the rest of the packages as the MariaDB packages are held to the current version or lower.

7. Uninstall a Package in Alpine Linux

To uninstall a package, use the syntax shown.

# apk del package-name

For example, to remove or uninstall the MariaDB package, run the command:

$ apk del mariadb
Remove Package in Alpine Linux
Remove Package in Alpine Linux

8. Get Help with APK

For additional options with an apk package manager, run the command:

# apk --help
Apk Command Help
Apk Command Help

Additionally, you can visit the man pages as shown

# man apk

This wraps up our guide on Alpine Linux apk commands. It’s our hope that you can now easily install and manage packages on Alpine Linux using the apk package manager.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.