Alpine Linux is a lightweight distribution which provides you with a command line interface and doesn’t come pre-installed on any machines, so it’s not easy for beginners. This walkthrough will teach you how to install Alpine in just two commands.
Alpine Linux is a lightweight, security-oriented and minimalistic distribution of the Linux operating system. It’s designed for small systems with low power requirements, such as routers, firewalls, VoIP gateways, etc. Alpine also has a package manager called “apk” that can be used to download and install software packages.
Every Linux distribution has its own package manager, which helps with software installation and management. We have an apt package manager for Debian/Ubuntu.
DNF is the package manager for RHEL and contemporary RedHat distributions like CentOS, Rocky Linux, and AlmaLinux. We have universal package managers like snap and flatpak, of course.
APK, or Alpine Package Keeper, is the package management tool in Alpine Linux. It searches web repositories for packages and information about them.
These repositories are divided into two branches:
- The primary repository
- Repository for the community
The The primary 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 The primary repository will always have replacements if they do not go past upstream.
The Repository for the community 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.
These repositories are found in the /etc/apk/repositories file on Alpine, and may be seen using the cat command.
/etc/apk/repositories/cat http://dl-cdn.alpinelinux.org/alpine/v3.15/main http://dl-cdn.alpinelinux.org/alpine/v3.15/community
Now let’s look at how to use the apk package manager to manage packages on Alpine Linux.
1. Alpine Linux Packages must be updated.
Before installing any software packages, it’s recommended to constantly update the local package listings. Run the following command to do this:
$ apk update Update Alpine Linux
2. Browse the Alpine Linux Repository for packages.
Alpine Linux repository include tens of thousands of software packages. Run the command to get a list of all the packages.
# apk find -v
The command above displays a big list of packages on the terminal, which isn’t very useful. Instead, you might look for a certain bundle that appeals to you.
Run the command to find all instances of nodejs, for example.
# apk find -v nodejs OR # apk find -v | grep -i nodejs Search Package in Alpine Linux
3. Install Alpine Linux Packages
Use the following syntax to install a package on Alpine Linux:
$ apk apk apk apk apk
To install Python3, for example, use the command:
$ apk add python3 Install Package in Alpine Linux
Additionally, you may use a single command to install numerous packages, as illustrated.
# add package1 package2 to apk
For example, use the following to install the Apache web server and MariaDB database server packages.
# apk add apache2 mariadb Install Packages in Alpine Linux
4. Make a list of the software packages that have been installed.
Run the apk info command to get a list of all installed packages:
# apk info List Installed Packages in Alpine Linux
Use the following syntax to check whether a given package is installed:
# apk package-name info
The output of the command is as follows:
- The package’s version number.
- A description of the bundle in a few words.
- The parent company’s website.
- The size of the installed system.
Run the following command to see whether MariaDB is installed:
# mariadb apk info
Use the -a flag to get specific information about a package.
# mariadb apk info
You may acquire more information using this information, such as
- Dependencies between packages.
- The package’s list of included packages.
- The packages that are likely to be impacted by autoinstallation.
5. Alpine Linux Package Upgrades
Run the following commands in order to update all packages on Alpine Linux:
# apk upgrade # apk download
These commands can be combined to form a single command, as shown below:
# apk -U upgrade Upgrade Package in Alpine Linux
It’s also a good idea to do a dry run of the update. This shows you how the packages will be updated while simulating the upgrade. The -s option may be used to do this.
# apk -s apk -s apk -s ap
6. Make a package ineligible for upgrade
You may need to prevent a software package from being updated at times. There are a variety of causes behind this. For example, a new version of a package could be problematic and prone to problems, so you might wish to stick with your existing version, which is compatible with other programs.
Use the syntax presented to prevent a package from being upgraded in Alpine Linux.
# apk package=version add
We’re preventing MariaDB version 10.6.7-r0 from being updated in the example below.
# apk add mariadb=10.6.7-r0 Exclude Package from Upgrade in Alpine Linux
As the MariaDB packages are held to the current version or lower, you may now update the rest of the packages.
7. Alpine Linux: Uninstall a Package
Use the syntax given to remove a package.
# apk package-name remove
Run the following command to deactivate or uninstall the MariaDB package:
$ apk del mariadb Remove Package in Alpine Linux
8. Seek assistance with APK.
Run the following command using an apk package manager for more options:
# apk –help Apk Command Help
You can also look at the man pages, as shown.
# man apk
This concludes our Alpine Linux apk commands tutorial. We hope that utilizing the apk package manager, you can now quickly install and manage packages on Alpine Linux.
The “Getting Started with Alpine Linux Apk Command Examples” is a tutorial that explains the difference between apk and apt-get. It also gives examples of how to use them in your command line. Reference: apk vs apt-get.
- alpine apk install
- apk add command
- apk list installed packages
- alpine linux packages
- alpine install package