Apk linux package manager

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:

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 http://dl-cdn.alpinelinux.org/alpine/v3.15/main http://dl-cdn.alpinelinux.org/alpine/v3.15/community 

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:

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

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 OR # apk search -v | grep -i nodejs

Search Package in Alpine Linux

3. Install Packages in Alpine Linux

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

For example, to install Python3, run the command:

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

Install Packages in Alpine Linux

4. List Installed Software Packages

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

List Installed Packages in Alpine Linux

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

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:

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

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:

These commands can be combined into one as follows:

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.

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.

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

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.

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

Remove Package in Alpine Linux

8. Get Help with APK

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

Apk Command Help

Additionally, you can visit the man pages as shown

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.

Читайте также:  Xampp on linux x64

Источник

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.

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

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:

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

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.

Get Package Description in Alpine Linux

4. Install Packages in Alpine Linux

To install packages on Alpine Linux, use the syntax:

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

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.

Install Multiple Packages in Alpine Linux

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

Читайте также:  Dev shm on linux

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

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

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.

Install Package Confirmation

5. Check Installed Package in Alpine Linux

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

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

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.

Check Package in Alpine Linux

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

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.

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.

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:

Find Installed Package Size in Alpine Linux

9. List All Installed Packages

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

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

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.

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.

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:

12. Remove a Package in Alpine Linux

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

For example, to delete vim, run the command.

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 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.

Источник

Оцените статью
Adblock
detector