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:
For example, we install the “neofetch” package using the following command:
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:
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:
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.
First, we install two packages, “neofetch” and “htop”, using their package name:
You can also install multiple packages with their specific versions.
Here, we install the same packages by specifying their versions.
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:
Install Multiple Local Packages
When you need to install the multiple local packages on Alpine Linux with all their dependencies, use the following command:
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:
Or
apk add <package_name> -i
Here, we install “htop” with an interactive option using the following command:
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:
We install “htop” without the local cache path:
Quiet
You can install a package without printing any details or information using the “quiet” option as follows:
Or
apk add <package_name> -q
For example, we install “htop” without printing any information through the following command:
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:
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.