Linux Commands

How to Install a Package on Alpine Linux

Every Linux distro has pre-installed package managers to install, uninstall, and manage the packages in the system. Alpine Linux also has its package manager which is known as Package Keeper APK. All versions of Alpine come pre-installed with Apk which allows you to perform many package management tasks including updating, searching, installing, uninstalling, listing, and more software packages. However, if you are a beginner in Alpine Linux, you may need a clarification while installing the package. In this short guide, we will explain the methods to install a package on Alpine Linux.

How to Install a Package on Alpine Linux

Let’s now divide this section into different parts to explain the approaches that you can try to install the packages on Alpine Linux:

Install a Package from the Alpine Repository

You can install any available package in the Alpine repository and its necessary dependencies. The general syntax of installing any package on Alpine Linux is as follows:

apk add <package_name>

For example, we install the “neofetch” package using the following command:

apk add neofetch

The previous command installs the neofetch along with all the dependencies it requires. Remember, add the command that installs the newest package if you have multiple repositories.

Install a Specific Package

You can install a specific version of any package that you want to install. You can follow the simple syntax for it:

apk add <package_name>=<version>

To do this, go to the official website of the Alpine Linux packages. After that, search for the package that you want to install and locate its version. Here, we install “htop”. For that, we find its version.

Now, we install the htop using the following command:

apk add htop=3.2.1-r1

Install Multiple Packages

You can install multiple packages at once because you only need to add the name of all the packages that you want to install with the add command.

apk add <package_name 1> <package_name 2>....

First, we install two packages, “neofetch” and “htop”, using their package name:

apk add neofetch htop

You can also install multiple packages with their specific versions.

apk add <package_name 1 with=version> <package_name 2=version>....

Here, we install the same packages by specifying their versions.

apk add neofetch=7.1.0-r1 htop=3.2.1-r1

Install a Local Package

You can install a locally available apk package. If your device doesn’t have internet, use the –allow-untrusted flag. For this, use the following command:

apk add --allow-untrusted /path/to/file.apk

Install Multiple Local Packages

When you need to install the multiple local packages on Alpine Linux with all their dependencies, use the following command:

apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk

Additional Options for Package Installation

There are several options while downloading the packages on Alpine Linux. With the help of which, you can modify the installation process of the package.

Interactive

You can use the “-i” or “—interactive” option to prompt the user interaction and ask for confirmation before installing the package. Using this option, you can force the confirmation before starting the installation process. Its syntax is something like this:

apk add <package_name> --interactive
Or
apk add <package_name> -i

Here, we install “htop” with an interactive option using the following command:

apk add htop --interactive

You can see that it asks you to continue the installation process. You can complete the installation process by typing “y” or abort the operation by typing “n”.

No Cache

While installing a package, if you don’t want to use the local cache path, you can use the “no-cache” option as follows:

apk add <package_name> --no-cache

We install “htop” without the local cache path:

apk add htop --no-cache

Quiet

You can install a package without printing any details or information using the “quiet” option as follows:

apk add <package_name> --quiet
Or
apk add <package_name> -q

For example, we install “htop” without printing any information through the following command:

apk add htop --quiet

As you can see, the previous command doesn’t print any details and installs “htop”.

Bonus Tip: If you have an older version of Alpine Linux and you want to install a new or updated package, you can use the following command:

apk add --update <package> && \
 rm -rf /var/cache/apk/*

Conclusion

This short guide explains how to install a package on Alpine Linux. You can easily install the packages with the help of the Alpine package manager, apk. You have to use the “apk add” command. We have seen many ways to install the packages, like installing the packages from the alpine repositories, installing the local packages, etc.

Apart from this, you can modify your installation process according to your own using many options which we provided with brief details in this tutorial.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.