Linux apk Command: Manage Packages on Alpine Linux

apk is the package management command for Alpine Linux. It is used for searching, adding, removing, and upgrading repository packages, and the procedure for preserving changes may vary depending on how Alpine is installed.

What is the apk command?

apk add adds packages to the desired system state, and apk del removes those constraints. The list of desired packages is recorded in /etc/apk/world. apk update refreshes the repository index, and apk upgrade updates installed packages. In diskless mode, a separate procedure may be needed to persist changes.

Basic syntax

apk [global options] command [package...]

The installed implementation and options may vary depending on the distribution. Check the current system's description with man apk.

Examples

Package search

Find candidates in the repository that match the name.

apk search nginx

Package Installation

Check for required dependencies and add them.

sudo apk add nginx

Refreshing repository information and upgrading

Check the difference between the two actions and review the list of changes.

sudo apk update
sudo apk upgrade

Distinguishing Between Installation Status and Repository Update

apk info -e checks whether a specified package is installed by name. In a default Alpine environment, if busybox is installed, it will appear as follows.

apk info -e busybox

Example output:

busybox

apk update only refreshes the repository index and does not change the version of installed packages. To actually upgrade installed packages, apk upgrade is required. In diskless mode or disposable containers, check according to your operational method if package changes persist after restarting or recreating.

Main Options and Format

Options/Format Description
search / info Find repository packages or view details.
add / del Add or remove desired package constraints.
update Update the repository index.
upgrade Upgrade installed packages to the latest possible versions.
--no-cache This is an option to reduce the use of the local package cache when executing commands.

Precautions when using

Installed packages are not upgraded with apk update alone. apk del may remove items depending on whether they are required by other packages, so check the suggestion list. In diskless/container environments, package changes need to be reflected in the image or management configuration to persist after recreation.

Frequently Asked Questions

What is the difference between apk add and apk update?

"add" installs the desired packages, and "update" updates the repository index. Version updates for installed packages are done with "upgrade".

Official Documentation

The exact behavior of the option and differences between implementations can be found in the official documentation related to apk.

More in This Category
Linux shred Command: Overwrite File Data and Understand Its Limits

Linux shred Command: Overwrite File Data and Understand Its Limits

Learn how Linux shred overwrites file data, which options control its passes and removal, and why SSDs, snapshots, backups, and modern filesystems limit its guarantees.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux tail Command: View the End of a File and Follow Logs

Linux tail Command: View the End of a File and Follow Logs

Learn how to use the Linux tail command to view the last lines of a file and follow log updates in real time, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux cut Command: Extract Characters and Fields

Linux cut Command: Extract Characters and Fields

Learn how to extract Characters and Fields with the Linux cut command, including practical examples, key options, and important precautions.

Linux more Command: View Text One Screen at a Time

Linux more Command: View Text One Screen at a Time

Learn how to use Linux more to read text one screen at a time, move and search interactively, start at a line or pattern, and choose between more and less.

Linux realpath Command: Resolve Absolute and Canonical Paths

Linux realpath Command: Resolve Absolute and Canonical Paths

Learn how to use the Linux realpath command to resolve relative paths, symbolic links, and redundant path components, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Practice searching, sorting, grouping, extracting, and counting text with grep, sort, uniq, cut, and wc, including reproducible output and key caveats.

Linux join Command: Combine Files by a Common Field

Linux join Command: Combine Files by a Common Field

Learn how to combine Files by a Common Field with the Linux join command, including practical examples, key options, and important precautions.