How to build and install Alpine Linux package with newapkbuild
newapkbuild that helps in creating a new .apk files provide complete instructions on how to specify data such as package's version, name, source URLs, description, and complete install procedures.
Here is the complete guide on how to build Linux package using newapkbuild.
Set up the environment
It is essential to prepare your environment by installing essential software before building packages.
Installing Alpine SDK
Update the package list and install the Alpine SDK. It includes newapkbuild and all the necessary tools required to create Alpine packages.
apk updateapk add alpine-sdk
Creating a new user
It is usually recommended to build packages by creating a new user. If you build the package as the root user, it may cause potential damage by the build scripts.
Create a new user, add it to abuild, and switch to the newly created user.
adduser -D new_Useraddgroup new_User abuildsu - new_User
Here,
Line 1: It creates a new user named
new_User. The-Dflag specifies that it is a system user.Line 2:
addgroupadds the newly created user to theabuildgroup. These groups in Linux are essential to control access to resources and manage permissions.
Line 3: It finally switches the current user to the new user.
Set up abuild
Before using abuild to build your packages, you need to generate a new RSA keypair.
Generating keypair
abuild-keygen -a i
The -a flag adds the newly created public key to the following directory.
|--etc|--apk|--keys
The -i flag installs the keypair to the home directory of the user $HOME/.abuild.
Create a new package
After preparing your environment, you are now ready to create a new package.
Generating a new apkbuild file
Use newapkbuild to generate a new apkbuild file. The given command creates a directory named my_new_package containing apkbuild file.
newapkbuild -n my_new_package -d "My first Alpine pakcage" -l "https://my_new_package.example.com" -s "git+https://git.example.com/my_new_package.git" -y "APGL-3.0-only" -a "x86_64"
In the above command,
-n: Specifies the name of the package-d: Gives description about the package-l: Sets the URL for where the package is to be hosted-s: Specifies the source repository of the package-y: Sets the license of the package-a: Sets the architecture the package should be build for
Note:
The apkbuild file is just a template. You will have to make necessary changes depending on the software you are packaging.
Read the Reference Document to understand how to write the apkbuild file.
Building the package
After completing the apkbuild file, you are now ready to build your package.
Building the package with abuild
Use abuild to build the package.
cd my_new_packageabuild -r
Line 2: The -r flag makes the abuild check for any missing dependencies and install them automatically.
Installing the package
After building the package, you can install it using apk package manager.
Installing the package with apk
Use apk to install the package.
sudo apk add /home/new_User/packages/main/x86_64/my_new_package-*.apk
Here,
sudo: Runs the followed command with superuser privileges.apk: Used to install, upgrade, and delete packages.add: Installs theapkpackage with the path to the package file you want to install.
Note:
If you want to distribute the package you have created to others, you need to host the compiled package on a server.
After that, distribute the public part of the RSA keypair.
Doing this allow others to verify that the package came from the original source and has not been tampered with.
You have now successfully built and installed a package on Alpine Linux.
Continue reading
Free Resources