Alpine Linux

How to change keyboard layout in Alpine Linux

You can easily change the keyboard layout in Alpine Linux by running

setup-keymap

This will first prompt you for your generic keyboard layout:

Available keyboard layouts:
af     ara    ba     bg     by     cm     de     ee     fi     gb     gr     id     in     is     ke     kz     lk     ma     mk     mt     nl     pk     ro     se     sy     tm     ua     vn
al     at     bd     br     ca     cn     dk     epo    fo     ge     hr     ie     iq     it     kg     la     lt     md     ml     my     no     pl     rs     si     th     tr     us
am     az     be     brai   ch     cz     dz     es     fr     gh     hu     il     ir     jp     kr     latam  lv     me     mm     ng     ph     pt     ru     sk     tj     tw     uz
Select keyboard layout: [none]

In my case, I just type de to select the German keyboard layout and press Enter.

After that, It will prompt you for the keyboard variant to use. For German keyboards this will look like this:

Available variants: de-T3 de-deadacute de-deadgraveacute de-deadtilde de-dsb de-dsb_qwertz de-dvorak de-e1 de-e2 de-mac de-mac_nodeadkeys de-neo de-nodeadkeys de-qwerty de-ro de-ro_nodeadkeys de-ru de-sundeadkeys de-tr de-us de
Select variant (or 'abort'):

If you don’t particularly care about the variant or if you don’t know what than means, just enter whatever you entered in the first step: If you entered de before, enter de again and press Enter.

Now Alpine will configure your Keyboard:

* WARNING: you are stopping a boot service
* Caching service dependencies ... [ ok ]
* Setting keymap ... [ ok ]

The new keymap will be effective immediately and it will also persist after a reboot.

Note that the Alpine Installer (which you can start using setup-alpine) will automatically ask you for the correct keymap – hence, it’s not neccessary to run setup-keymap before running the installer.

Posted by Uli Köhler in Alpine Linux

How to autostart service from /etc/init.d on Alpine Linux

In order to autostart a service on Alpine Linux, use

rc-update add [service] default

For example, autostart docker using

rc-update add docker default

 

Posted by Uli Köhler in Alpine Linux

How to install XCP-NG Guest Utilities on Alpine Linux

At the time of writing this, the XCP-NG guest tools ISO does not support Alpine Linux, but you can install the guest utilities using

apk add xe-guest-utilities

Additionally, you need to enable starting the Xen guest utilities on startup:

rc-update add xe-guest-utilities default

Now we can start the utilities manually in order to avoid having to reboot:

/etc/init.d/xe-guest-utilities start
Posted by Uli Köhler in Alpine Linux

How to fix Alpine Linux ERROR: ‘install’ is not an apk command

Problem:

You are trying to install an apk package using e.g.

apk install python

but you see this error message:

ERROR: 'install' is not an apk command. See 'apk --help'.

Solution:

Use apk add instead of apk install to install packages on Alpine Linux !

So instead of

apk install python

use

apk add python

 

Posted by Uli Köhler in Alpine Linux

How to fix Alpine Linux -ash: sudo: not found

Many users who are used to classical Linux distributions will see the following error message when using sudo on Alpine Linux:

-ash: sudo: not found

You don’t need sudo in many use cases!

The easiest way to fix that is to just run the command as root.

In order to get into a root shell (if you are not already logged in as root), use

su

which expects you to enter the root password.

Now just run the original command without sudo.

Still want to install sudo?

If you still want to install sudo, just run

apk add sudo

This is often the best approach if you have e.g. scripts that are running sudo commands.

Posted by Uli Köhler in Alpine Linux

How to install docker & docker-compose on Alpine Linux

In this post, we’ll show how to install docker-compose (and the docker backend) on Alpine Linux.

Step 1: Enable the apk community repository

Edit the repository config as root using

vi /etc/apk/repositories

It should look like this (the exact URLs will vary according to your selected mirror)

#/media/cdrom/apks
http://ftp.halifax.rwth-aachen.de/alpine/v3.13/main
#http://ftp.halifax.rwth-aachen.de/alpine/v3.13/community
#http://ftp.halifax.rwth-aachen.de/alpine/edge/main
#http://ftp.halifax.rwth-aachen.de/alpine/edge/community
#http://ftp.halifax.rwth-aachen.de/alpine/edge/testing

Now find the line that ends in /communityand does NOT end with /edge/communityTypically, this is the second line in the file:

#http://ftp.halifax.rwth-aachen.de/alpine/v3.13/community

Navigate to this line by using the arrow keys, press the Insert key in order to activate Editing.

Then remove the # at the beginning of the line. The resulting file should look like this:

#/media/cdrom/apks
http://ftp.halifax.rwth-aachen.de/alpine/v3.13/main
http://ftp.halifax.rwth-aachen.de/alpine/v3.13/community
#http://ftp.halifax.rwth-aachen.de/alpine/edge/main
#http://ftp.halifax.rwth-aachen.de/alpine/edge/community
#http://ftp.halifax.rwth-aachen.de/alpine/edge/testing

Now save the file an exit the editor by pressing the Esc key, entering :wq and pressing enter.

Step 2: Install docker & docker-compose

Now we’ll fetch the package lists using

apk update

After that, we can install docker and docker-compose using

apk add docker docker-compose

Step 3: Enable docker daemon autostart & start docker daemon

Enable autostart on boot using

rc-update add docker default

and then start docker using

/etc/init.d/docker start
Posted by Uli Köhler in Alpine Linux

How to check / enable DHCP in Alpine Linux installer

Once you have booted from the Alpine Linux installer CD and logged in using root<no password> as described in What is the Alpine linux default login & password?, one often wants to test if DHCP works before going through the installer and potentially having to repeat the process.

First enable Ethernet using

ifconfig eth0 up

Then run the DHCP client using

udhcpc eth0

This will show you the IP address of the lease that your Alpine Live CD did acquire.

Posted by Uli Köhler in Alpine Linux, Linux, Networking

How to install python3 pip / pip3 in Alpine Linux

Problem:

You want to install pip3 (also called python3-pip) in Alpine linux, but running apk install python3-pip shows you that the package doesn’t exist

/ # apk add python3-pip
ERROR: unable to select packages:
  python3-pip (no such package):
    required by: world[python3-pip]

Solution:

You need to install py3-pip instead using

apk add py3-pip

Example output:

/ # apk add py3-pip
(1/35) Installing libbz2 (1.0.8-r1)
(2/35) Installing expat (2.2.10-r1)
(3/35) Installing libffi (3.3-r2)
[...]

 

Posted by Uli Köhler in Alpine Linux, Container, Docker, Linux

How to fix Alpine Linux fatal error: stdio.h: No such file or directory

Problem:

When trying to compile a C/C++ program or library on Alpine Linux, you see an error message like

/home/user/test.cpp:5:10: fatal error: stdio.h: No such file or directory
  123 | #include <stdio.h>
      |          ^~~~~~~~~

Solution:

Install the libc headers using

apk add musl-dev

 

Posted by Uli Köhler in Alpine Linux, C/C++, GCC errors, Linux

What is the Alpine linux default login & password?

The Alpine Linux installation ISO uses root as the default user and an empty password. In order to login, just enter the username root and press return.

Posted by Uli Köhler in Alpine Linux, Linux