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.
- The main repository comprises packages that are rigorously tested and approved to be officially hosted by the Alpine Linux core development team.
- 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
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
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
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
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
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
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.
To confirm that vim editor is installed, simply run the vim command without any arguments and this will display information about vim.
$ vim
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
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
To list additional information such as the version and size of the installed package simply run:
$ apk info nano
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
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
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
9. List All Installed Packages
To list all installed packages on Alpine Linux, run the command:
$ apk info
10. Upgrade Alpine Linux
To upgrade all the packages on Alpine Linux to their latest versions, run the command
$ apk upgrade
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
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
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
13. Getting Help with Apk Command
For additional apk commands, you can browse the apk help catalog as shown
$ apk --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.
The above is the detailed content of 13 Apk Commands for Alpine Linux Package Management. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and

Data replication is the process of copying your data across multiple servers to improve data availability and enhance the reliability and performance of an application. In MySQL replication, data is copied from a database from the master server to ot
