Alpine Linux

How to list installed files for package on Alpine Linux

In order to list the installed files for an Alpine package such as dropbear, use

apk info -qL NAME_OF_PACKAGE

For example:

# apk info -qL dropbear
usr/bin/dropbearkey
usr/sbin/dropbear

Note: This might list the installed files for the most recent version of the package, not the installed package.

Posted by Uli Köhler in Alpine Linux

How to correctly use apk in Dockerfile

In Dockerfiles you should always use apk with --no-cache to prevent extra files being deposited on the containers, for example:

FROM alpine:3.17
RUN apk add --no-cache python3-dev

 

Posted by Uli Köhler in Alpine Linux, Docker

How to install bup on Alpine Linux

In order to install the bup backup software on Alpine Linux, you currently have to compile it yourself.

First, install the prerequisites:

apk add bash make g++ python3-dev git automake autoconf par2cmdline py3-pip && pip3 install wheel && pip3 install pyxattr

Now we can clone bup:

git clone -b 0.33 --depth 1 https://github.com/bup/bup

and build:

cd bup && ./configure && make -j4 install PREFIX=/usr

After this, bup should be installed in /usr/bin/bup. The bup clone directory we created in the first step is not needed any more.

Posted by Uli Köhler in Alpine Linux, bup

How to install “autom4te” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you sometimes see messages like

sh: autom4te: not found
aclocal: error: autom4te failed with exit status: 127

but when you try to apk install autom4te you see that the package can not be found:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  autom4te (no such package):
    required by: world[autom4te]

Solution:

autom4te is available from the autoconf package. Therefore, in order to fix the issue, you can run

apk install autoconf

 

Posted by Uli Köhler in Alpine Linux

How to install “aclocal” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you sometimes see messages like

./automake.sh: line 5: aclocal: not found

but when you try to apk install aclocal you see that the package can not be found:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  aclocal (no such package):
    required by: world[aclocal]

Solution:

aclocal is available from the automake package. Therefore, in order to fix the issue, you can run

apk install automake

 

Posted by Uli Köhler in Alpine Linux

How to install “cpp” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you often see messages like

Looking for cpp (not found)

but when you try to apk install cpp you see an error message like

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  cpp (no such package):
    required by: world[cpp]

Solution:

cpp is just an alias for any C++ compiler. In practice, that means either installing clang++ or g++. I typically recommend g++, even though both will work for most applications.

Therefore, in order to fix the issue, you can run

apk install g++

 

Posted by Uli Köhler in Alpine Linux

How to autostart Wireguard (wg-quick) on boot on Alpine Linux

If you have a Wireguard config file such as /etc/wireguard/wghome.conf, which you can start manually using wg-quick up wghome, this is how you autostart it on boot. Thanks to Justin Ludwig on Serverfault for the template for that init script

Create /etc/init.d/wg-quick-wghome:

#!/sbin/openrc-run
description="wg-quick wghome"

depend() {
    need net
    need localmount
}

start() {
    wg-quick up schlaftier
}

stop() {
    wg-quick down schlaftier
}

Then make it executable:

chmod a+x /etc/init.d/wg-quick-wghome

and enable it to start on boot:

rc-update add wg-quick-wghome default

and start it right now if desired:

/etc/init.d/wg-quick-wghome start

Of course you can add multiple scripts like this. Just ensure to name them differently and perform all the steps required to enable startup on boot.

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

How to enable IPv4 forwarding in Alpine Linux

You can run this simple command as root to enable IPv4 forwarding in Alpine Linux:

sysctl -w net.ipv4.ip_forward=1

This setting will not persist after reboot.

In order to make the setting persist, append net.ipv4.ip_forward=1 to /etc/sysctl.conf:

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

 

Posted by Uli Köhler in Alpine Linux, Networking

How to fix Alpine Linux wg-quick (no such package)

Problem:

While trying to install wg-quick on Alpine Linux, you see the following error message:

ERROR: unable to select packages:
  wg-quick (no such package):
    required by: world[wg-quick]

Solution:

You need to install the wireguard-tools package which also contains wg-quick:

apk add wireguard-tools

 

Posted by Uli Köhler in Alpine Linux, Wireguard

How to permanently enable IPv4 forwarding in Alpine Linux

This simple command will permanently enable IPv4 forwarding on Alpine Linux. Run this as root:

echo net.ipv4.ip_forward=1 | tee -a /etc/sysctl.conf && sysctl -p

 

Posted by Uli Köhler in Alpine Linux, Networking

How to install tailscale in Alpine Linux

My recommendation is to just use the community repository:

echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories
apk add -U tailscale

Now you need to add tailscaled to the autostart list and then start the service so you can use it right now:

rc-update add tailscale
/etc/init.d/tailscale start

 

Posted by Uli Köhler in Alpine Linux

How to install usermod in Alpine Linux

Problem:

When trying to use usermod in Alpine Linux, you see the following error message:

-ash: usermod: not found

Solution:

Install usermod and related tools by adding the community repositories and using

echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories
apk add -U shadow

 

Posted by Uli Köhler in Alpine Linux

How to install glib-2.0 development headers on Alpine Linux

First run

apk update

as root to update the list of available packages. After that, install the glib 2.0 development files using

apk add glib-dev

 

Posted by Uli Köhler in Alpine Linux

How to install pkg-config on Alpine Linux

First run

apk update

as root to update the list of available packages. After that, install pkg-config using

apk add pkgconfig
Posted by Uli Köhler in Alpine Linux

How to install CMake on Alpine Linux

Run

apk update

as root to update the list of available packages. Then, run

apk add cmake

to install CMake.

Posted by Uli Köhler in Alpine Linux

How to automount CIFS/SMB on Alpine Linux

In order to automatically mount CIFS on boot of an Alpine Linux instance, use a line like this in /etc/fstab:

//1.2.3.4/mydrive /mydrive   cifs uid=1000,gid=1000,credentials=/root/.smb-credentials,iocharset=utf8,noperm 0 0

with a standard /root/.smb-credentials like this:

user=myuser
password=raatahteiC1veiza8ahno8lu5quook

and run the following command to enable automount on boot:

rc-update add netmount boot

After a reboot, the filesystem should mount automatically.

Posted by Uli Köhler in Alpine Linux, Networking

How to install python-config on Alpine Linux

I recommend to use Python 3.x since Python 2.x is deprecated!

Installing python-config for Python 3.x

The python3-dev apk package provides /usr/bin/python3-config, so you’ll have to symlink that to /usr/bin/python-config:

apk update
apk add python3-dev
ln -sf /usr/bin/python3-config /usr/bin/python-config

Installing python-config for Python 2.x

Just install python2-dev, which installs /usr/bin/python-config

apk update
apk add python2-dev

 

 

Posted by Uli Köhler in Alpine Linux

How to install ruby & rubygems in Alpine Linux

Problem:

You want to install ruby and the gem package manager in Alpine linux, but running apk install ruby rubygems shows you that the package doesn’t exist

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

Solution:

gem is included in the ruby package. So the only command you need to run is

apk update
apk add ruby

Example output:

/ # apk add ruby
(1/7) Installing ca-certificates (20191127-r5)
(2/7) Installing gdbm (1.19-r0)
(3/7) Installing gmp (6.2.1-r0)
(4/7) Installing readline (8.1.0-r0)
(5/7) Installing yaml (0.2.5-r0)
(6/7) Installing ruby-libs (2.7.3-r0)
(7/7) Installing ruby (2.7.3-r0)
Executing busybox-1.32.1-r6.trigger
Executing ca-certificates-20191127-r5.trigger
OK: 928 MiB in 154 packages

After doing that, you can immediately use both ruby and gem.

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

How to enable SSH root login on Alpine Linux

Note: Be aware that enabling root access via SSH has security implications!

On Alpine Linux, root SSH access using passwords is disabled by default. The following tutorial shows you how to enable password-based root login via SSH when using openssh. (I have not tested whether root access is enabled when installing Alpine Linux using dropbear instead of openssh)

First, open the SSH config file using

vi /etc/ssh/sshd_config

Now look for this line:

#PermitRootLogin prohibit-password

Press I in order to activate vi editing mode.

Remove the # at the beginning of the line and change prohibit-password to yes:

PermitRootLogin yes

Now save and exit by pressing Esc and then pressing :wq and Enter.

After that, restart openssh using

service sshd restart

Now you can login as root using the password.

Posted by Uli Köhler in Alpine Linux