/about /posts /pages

Building Alpine Packages with chroot (using `alpine-chroot-install`)

2026-05-19

Backstory

Initially, I did not want to bother using chroot to setup an Alpine developer environment, because it seems it would require a bit more manual work to setup. However, after playing around with it, it seems to be a bit more convient if you want to do a bit more than just apkbuild-pypi create xyz. So, let's get to it.

Setup

First, fetch the alpine-chroot-setup script from the GitHub Repository:

wget https://raw.githubusercontent.com/alpinelinux/alpine-chroot-install/v0.14.0/alpine-chroot-install
echo 'ccbf65f85cdc351851f8ad025bb3e65bae4d5b06  alpine-chroot-install' | sha1sum -c  || exit 1

Then, using the script, we can already bootstrap the environment:

sudo ./alpine-chroot-install    \
    -b edge                     \
    -p alpine-sdk               \
    -p atools                   \
    -p git                      \
    -p openssh                  \
    -p doas                     \
    -r https://dl-cdn.alpinelinux.org/alpine/edge/testing

The script will then:

We then could enter the chroot (with our current user) by just running the script in the newly created directory (alpine/):

/alpine/enter-chroot -u $USER

But, we still need to generate the keys, setup abuild and prepare the git config. Let's do that first:

# add our current host user to the `abuild` and `wheel` groups
/alpine/enter-chroot addgroup $USER wheel
/alpine/enter-chroot addgroup $USER abuild

# enable users in the `wheel` group to use `doas` without password
/alpine/enter-chroot sed 's/# permit persist/permit nopass/g' -i /etc/doas.conf

# for package maintainers, add our name and mail to the `abuild` conf
/alpine/enter-chroot sed 's/#PACKAGER=.*/PACKAGER="John Doe <john@doe.com>"/g' -i /etc/abuild.conf
/alpine/enter-chroot sed 's/#MAINTAINER/MAINTAINER/g' -i /etc/abuild.conf

# create keys
/alpine/enter-chroot -u $USER abuild-keygen -a -i -n

Finally, the setup is done, we can now enter the chroot and work directly in there (or, as before invoke commands directlty):

/alpine/enter-chroot -u $USER

Then, for example clone our fork of the aports repository, work on a package and build it:

git clone git@gitlab.alpinelinux.org:<your-fork>/aports.git
cd aports/testing/zot
abuild -r
...

Uninstall

Important: when you want to remove the chroot environment, you must use the given script destroy and not just do a rm -rf alpine/, otherwise you will also delete your mounted (virtual) filesystems (/dev, ...) leading to a bricked system:

/alpine/destroy --remove

Conclusio

This post introduces another way how to setup an Alpine developer environment, this time using a chrooted environment with the official bootstrap script alpine-chroot-script. Contrary to the previous post, this allows for a more long-living environment, although, I dislike the required manual steps as it's a less declarative approach. But, maybe some of these steps could also be integrated in the bootstrap script as a feature.