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 whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux shutdown Command: Schedule a Shutdown or Restart

Linux shutdown Command: Schedule a Shutdown or Restart

Learn how to schedule a Shutdown or Restart with the Linux shutdown command, including practical examples, key options, and important precautions.

Linux apk Command: Manage Packages on Alpine Linux

Linux apk Command: Manage Packages on Alpine Linux

Learn how to manage Packages on Alpine Linux with the Linux apk command, including practical examples, key options, and important precautions.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.

Linux tac Command: Print Lines in Reverse Order

Linux tac Command: Print Lines in Reverse Order

Learn how Linux tac prints records from last to first, handles multiple files and custom separators, and helps inspect recent log entries in reverse order.

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Learn how to use the Linux sudo command to run approved commands with elevated privileges or as another user, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Practice creating, copying, renaming, moving, and deleting files and directories in a dedicated folder while checking each result safely.

Linux unzip Command: List and Extract ZIP Archives

Linux unzip Command: List and Extract ZIP Archives

Learn how to list and Extract ZIP Archives with the Linux unzip command, including practical examples, key options, and important precautions.

Linux dd Command: Copy and Convert Data by Blocks

Linux dd Command: Copy and Convert Data by Blocks

Learn how to copy and convert files or block devices with Linux dd, choose block sizes and ranges, display progress, verify results, and avoid overwriting the wrong device.