Installing Alpine Linux on the Pi


Alpine Linux, smaller and better

by Craig Miller

Of course there is PiOS for the Raspberry Pi, but there are other distros which offer different features or benefits over PiOS. Alpine Linux is one of them. Alpine Linux is designed for embedded systems, and therefore by default, takes up less disk space, and less RAM (memory), which makes it very useful for Linux Containers (LXD).

Additionally Alpine Linux is not based on glibc, which recently had a vulnerability which impacted Loony Tuneables. Rather it is based on musl libc a smaller c-library.

Another key difference, is the package manager, Alpine Linux is not a derivative of Red Hat or Debian, and therefore uses apk as a package manager. To find out more about the package manager type the following in a terminal:

apk --help

Downloading the image

Alpine Linux has install images for many platforms. Scroll down to the Raspberry Pi section. Be sure to get the AARCH64, unless you are running an Pi 2 of less.

Create a bootable VFAT SD Card

The Alpine Linux image is actually just a tar file. Rather than using the PiOS Imager or BalenaEtcher, you simply format an SD card as VFAT, and make it bootable. This can be done with fdisk, or any tool you usually use to create VFAT SD Cards.

Linux Mint has a nice utility called usb stick formatter, which makes formatting an SD Card easy, including setting the Volume Label.


I find gparted to be an easy way to set the boot flag of the SD Card

Setting the boot flag

Alpine Linux has an excellent wiki full of how-to's including how to format a VFAT SD Card using the CLI, should you need it.

Untarring to a VFAT SD Card

After formatting the SD card, cd into it, and untar the alpine tarball

export USER=myuser
cd /media/$USER/ALPINE
tar xvf /home/$USER/Downloads/alpine-rpi-3.18.4-aarch64.tar.gz

Booting and installing from the VFAT SD Card

Alpine Linux will boot, and reside in memory, so it can re-write to the SD Card. You must have a screen attached to the Pi at this point, as there is no remote way to login headless.

You will be presented (on the screen) with a black text-based terminal. Log in as root (no password). Alpine Linux can get away with not having a root password, because there is no remote access when booting from the install disk (SD Card).

Alpine Linux has several disk modes of operation. After all, it is often used in embedded applications, and therefore having a fully read/write disk may not be necessary, or even desired!

The disk mode choices are:

To run Alpine Linux as a desktop computer (with X11 GUI), select sys

Alpine Linux has a collection of setup scripts to help the user in setting up the OS. We'll start with setup-alpine, which will ask several questions such as keyboard type, hostname, root password, disk mode, etc.

# setup-alpine
  Setup new user 'yes'
  Selected disk mmcblk0
    select 'sys'

After setup-alpine is done, it will have written the changes to the SD card (by selecting 'sys' disk mode) and a reboot is required to load the newly configured system.

reboot now

Installing the Desktop GUI

Once the system has rebooted (still using the attached screen and keyboard), you will be asked to log-in. Use the new user defined in setup-alpine. This user will have sudo privileges.

Once logged in, you will be presented with a black terminal screen (again). Let's setup X11 GUI. By default the GUI will use the XFCE desktop.

There is another setup script that will assist in installing the X11 server and GUI, called setup-xorg-base.

This script can also take a list of additional packages to be installed.

setup-xorg-base xfce4 xfce4-terminal xfce4-screensaver lightdm-gtk-greeter dbus 

Then we need to start some of the new services, and configure them to start at every boot:

rc-service dbus start
rc-update add dbus 
rc-update add lightdm
rc-service lightdm start    

Lastly, to make startup clean, reboot.

reboot now

Ooops X won't start

After reboot, you quickly figure out that X11 isn't running, so you still only have a big black terminal window.

Turns out there is a video driver module fbdev that hasn't been installed. Use the package manager to add the video driver.

sudo apk add xf86-video-fbdev

And start the X11 greeter, lightdm, which will start the GUI, and ask for a log-in (in the GUI).

rc-service lightdm start         # now GUI starts

Now there is a X11 Desktop, asking for a log-in.

Installing Firefox

OK, so now we have an X11 Desktop (XFCE), but what can we do with it?

Well one of the first things you probably want to do with a desktop is to use a web browser. Firefox is the browser of choice, but chromium is also in the repo.

Add the community repository to /etc/apk/repositories by uncommenting the following line with your favourite editor:


apk update
apk add libx11-dev libxft-dev libxinerama-dev ttf-dejavu
apk add firefox-esr

This will pull in a lot of packages. And when it is done, Firefox will be available in the Applicaitons->Internet menu. It isn't fast, but it does run on a Pi 3B+. Clearly a faster Pi, such as the 4 or the 5 would give a better Desktop experience.

Enabling X11 forwarding

I find it useful to be able to not only be able to remotely log in to my Pi's, but also to run X applications (such as GUI editors). In order to do this, one must enable X11 forwarding on the sshd server.

Using an editor, edit the file /etc/ssh/sshd_config and change the following lines to uncommented and 'yes'

X11Forwarding yes
X11DisplayOffset 10

Then restart the sshd server

/etc/init.d/sshd restart

Now (assuming you put the IP address in your DNS) you can remotely log-in to the Pi, and run GUI applications.


Start up the Pi with Alpine Linux running a GUI (XFCE Desktop)

Running Firefox

More notes about Alpine Linux

Alpine Linux takes a minimal approach to what is installed in running. It doesn't assume that you will want a GUI (as seen above) and therefore it doesn't install one automatically.

You may find that when installing applications, that additional libraries may be needed, because those libraries were not installed by default. This is on purpose. Having less run on your system, means your system is more secure. The only things running are things you put on the system.

And.... Alpine Linux is systemd-free thus eliminating a lot of baggage. Additionally it has direct support for lxd (Linux Containers) without all the non-sense of snapd.

Smaller foot print, less baggage

Alpine Linux is developed for embedded systems, but has enough packages to support a full Desktop Environment, and it has excellent support for IPv6. While running X11 GUI Desktop, the system takes about half the memory that PiOS requires, allowing you to bring life back to those older Pi's you have laying around.


25 October 2023