Software management: Difference between revisions

From Alpine Linux
No edit summary
m (Change Arch Linux bootstrap download to zst)
 
(64 intermediate revisions by 11 users not shown)
Line 1: Line 1:
If you want to run [https://www.gnu.org/software/libc/ glibc] programs in Alpine Linux, there are a few ways of doing so.  You could install glibc as additional to [https://musl.libc.org/ musl] (you would have to do this manually), or you could do it the easy way and use either Flatpak (the easiest) or a chroot.<br>
This page documents various ways to manage software in Alpine Linux. [[#Graphical software manager|Graphical software managers]] are available to supplement [[#Alpine Package Keeper|apk]] to manage official software packages along with [[#Flatpak|Flatpaks]].


Because there are different use cases, this is just a slight overview about what's possible and what's intelligent.<br>
This page also documents ways to [[#Running glibc programs|run software compiled with glibc]] including graphical programs like {{ic|Visual Studio Code}}, {{ic|google-chrome}}, {{ic|obsidian}} etc...


== Alpine package keeper ==
{{Main|Alpine Package Keeper}}
The official package manager in Alpine Linux [[Alpine Package Keeper|Alpine Package Keeper(apk)]] is a cli tool. [[Comparison_with_other_distros#Comparison_chart/Rosetta_Stone|Rosetta stone]] shows how standard package management tasks are done in Alpine Linux compared to other popular distributions.


= Your options =
== Graphical software manager ==
 
The following graphical tools are available to manage software packages from [[Repositories|official repositories]] and [[#Flatpak|Flatpaks]].
 
=== Gnome software ===
 
Gnome [[GNOME#Configuration|Software]] can be used as a GUI front end for apk for managing official software packages and flatpaks.
 
=== KDE Discover ===
 
KDE [[KDE#Discover|Discover]] can be used as a GUI front end for apk for managing official software packages and flatpaks.


== Flatpak ==
== Flatpak ==
{{Main|Flatpak}}


Flatpak is by far the easiest method of running any graphical glibc program on Alpine.
[[Flatpak#Installing_Flatpak|Flatpak]] is by far the easiest method for running programs not available in the official Alpine Linux [[Repositories|repositories]]. To use flatpaks, ensure that [[Flatpak#Installing_Flatpak|Flathub repository]] is enabled.
Firstly install it.


sudo apk add flatpak
== Running glibc programs ==


Then you can run any Flatpak application:
If you want to run [https://www.gnu.org/software/libc/ glibc] programs in Alpine Linux, there are a few ways of doing so.


flatpak run <flatpak name>
For simpler binaries, you can install [[#gcompat|gcompat]] a compatibility layer or you could do it the easy way and use [[#Flatpak|Flatpaks]]. See [[#Containers|containers]] or [[#Chroot|chroot]] section for ways to run glibc programs including graphical ones.


It is recommended to enable [https://flathub.org Flathub] using it's instructions [https://flatpak.org/setup/Alpine/ here], as most glibc programs you might need will be packaged there.
=== gcompat ===


You can then install applications from it, for example:
[https://git.adelielinux.org/adelie/gcompat gcompat] is a library which provides glibc-compatible APIs for use on musl libc systems like Alpine Linux. To install issue the command: {{cmd|apk add {{pkg|gcompat}}}}
After that you run your binaries as normal.


flatpak install com.valvesoftware.Steam
For an usage example, refer [[Firefox#DRM_content_using_Widevine_workaround|Firefox]] page, where gcompat is used to run glibc compiled Widevine binary.


== Chroot ==
== Chroot ==
{{Main|Chroot}}
An option that's easier to generalize to other glibc applications is installing a glibc-based distribution into a chroot. You can then either chroot into it, or use a symlink and some configuration to make its glibc (and associated libraries) usable from Alpine.
{{Tip|The most reliable way to enter a chroot is to use the [[Chroot#Enter_chroot|start-chroot]] script.}}
After setting up a chroot using any of the methods described below, the loader can be set up in Alpine like so (these instructions are for a Debian chroot in /var/chroots/debian, on x86_64, but can be adapted to other systems by using the appropriate paths):
{{cmd|mkdir -p /lib64
ln -s /var/chroots/debian/lib/x86_64-linux-gnu/ld-2.33.so /lib64
printf '/var/chroots/debian/lib/x86_64-linux-gnu\n/var/chroots/debian/usr/lib/x86_64-linux-gnu\n' > /etc/ld.so.conf
/var/chroots/debian/sbin/ldconfig}}


=== Gentoo Linux ===
=== Gentoo Linux ===
Line 29: Line 54:
Select a stage3 from [https://www.gentoo.org/downloads/ here] and portage latest from [https://www.gentoo.org/downloads/mirrors/ here] at gentoo/snapshots/portage-latest.tar.xz.
Select a stage3 from [https://www.gentoo.org/downloads/ here] and portage latest from [https://www.gentoo.org/downloads/mirrors/ here] at gentoo/snapshots/portage-latest.tar.xz.


First,
First,{{cmd|doas apk add {{pkg|xz}}}}
 
sudo apk add xz


Enter the chroot:
Enter the chroot:
mkdir ~/chroot
{{cmd|mkdir ~/chroot
cd ~/chroot
cd ~/chroot
tar -xvf stage3-*.tar.xz
tar -xvf stage3-*.tar.xz
tar -xvf portage-latest.tar.xz
tar -xvf portage-latest.tar.xz
mv portage usr
mv portage usr
sudo mount --bind /dev dev
doas mount --bind /dev dev
sudo mount --bind /sys sys
doas mount --bind /sys sys
sudo mount -t proc proc proc
doas mount -t proc proc proc
cp /etc/resolv.conf etc
cp /etc/resolv.conf etc
sudo chroot . /bin/bash
doas chroot . /bin/bash}}


And voilà, you have your working Gentoo chroot!<br>
And voilà, you have your working Gentoo chroot!<br>
Line 56: Line 79:
CHROOT_PATH="/home/$USER/chroot"
CHROOT_PATH="/home/$USER/chroot"
cd $CHROOT_PATH
cd $CHROOT_PATH
mount | grep $CHROOT_PATH/dev || sudo mount --bind /dev dev
mount | grep $CHROOT_PATH/dev || doas mount --bind /dev dev
mount | grep $CHROOT_PATH/sys || sudo mount --bind /sys sys
mount | grep $CHROOT_PATH/sys || doas mount --bind /sys sys
mount | grep $CHROOT_PATH/proc || sudo mount -t proc proc proc
mount | grep $CHROOT_PATH/proc || doas mount -t proc proc proc
cp /etc/resolv.conf etc
cp /etc/resolv.conf etc
sudo chroot --userspec=$USER:users . /bin/bash
doas chroot --userspec=$USER:users . /bin/bash
echo "You must manually unmount $CHROOT_PATH/dev, $CHROOT_PATH/sys, $CHROOT_PATH/proc."
echo "You must manually unmount $CHROOT_PATH/dev, $CHROOT_PATH/sys, $CHROOT_PATH/proc."
</nowiki>
</nowiki>
Line 68: Line 91:


=== Arch Linux ===
=== Arch Linux ===
 
{{Seealso|Installing ArchLinux inside an Alpine chroot}}
Either use '''pacstrap''' (included with the arch-install-scripts package) or an Arch bootstrap image:
Either use '''pacstrap''' (included with the arch-install-scripts package) or an Arch bootstrap image:


  sudo apk add arch-install-scripts
{{cmd|doas apk add {{pkg|arch-install-scripts}}
  mkdir ~/chroot && cd ~/chroot
mkdir ~/chroot && cd ~/chroot
  curl -O https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-2019.02.01-x86_64.tar.gz
curl -O https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.zst
  sudo tar xzf archlinux-bootstrap-2019.02.01-x86_64.tar.gz && rm archlinux-bootstrap-2019.02.01-x86_64.tar.gz
doas tar -x --zstd -f archlinux-bootstrap-x86_64.tar.zst && rm archlinux-bootstrap-x86_64.tar.zst
  sudo sed -i '/evowise/s/^#//' root.x86_64/etc/pacman.d/mirrorlist
doas sed -i '/evowise/s/^#//' root.x86_64/etc/pacman.d/mirrorlist
  sudo sed -i '/CheckSpace/s/^/#/' root.x86_64/etc/pacman.conf
doas sed -i '/CheckSpace/s/^/#/' root.x86_64/etc/pacman.conf
  sudo arch-chroot root.x86_64
doas arch-chroot root.x86_64
  [chroot]# pacman-key --init
[chroot]# pacman-key --init
  [chroot]# pacman-key --populate archlinux
[chroot]# pacman-key --populate archlinux}}


Once that is done, update the system and install the desired package(s) (denoted by ''"foo"'' in this example):
Once that is done, update the system and install the desired package(s) (denoted by ''"foo"'' in this example):
    
    
  [chroot]# pacman -Syu ''foo''
{{cmd|[chroot]# pacman -Syu ''foo''}}


=== Debian ===
=== Debian ===


Use the provided debootstrap package to create the Debian chroot. <code>--arch</code> is optional, depending of your needs.
Alpine Linux provides {{pkg|debootstrap}} package to create the Debian chroot. Here are the steps: {{cmd|<nowiki># apk add debootstrap
# mkdir -p /var/chroots/debian
# debootstrap --arch amd64 stable /var/chroots/debian/ https://deb.debian.org/debian </nowiki>}}
 
The {{ic|--arch}} is optional, depending on your needs.
 
For updating the Chroot or for installing applications i.e packages and their dependencies using {{ic|apt-get}}, mount it and then login as root:
{{cmd|<nowiki># mount --bind /dev /var/chroots/debian/dev
# mount --bind /proc /var/chroots/debian/proc
# mount --bind /dev/pts /var/chroots/debian/dev/pts
# chroot /var/chroots/debian /bin/bash
[chroot]# apt update && apt upgrade</nowiki>}}
 
After installing the necessary applications and what you might want to do, exit the chroot and umount the binds for /dev/pts, dev and proc to avoid issues.
{{cmd|<nowiki># umount /var/chroots/debian/dev/pts
# umount /var/chroots/debian/dev
# umount /var/chroots/debian/proc</nowiki>}}
 
== Containers ==
 
=== Distrobox + Podman ===
 
[[Distrobox]] combined with [[Podman|podman]] container running in rootless mode allows running [[Distrobox#Running_graphical_programs|glibc compiled graphical programs]] easy. This doesn't require root privileges once set up.
 
=== Bubblewrap + Chroot===
 
A script {{ic|glibc}} is used to create a container using [[Bubblewrap]] where a [[#Debian|Debian chroot]] is the content of that container. It's not just a chroot anymore; it's a bubblewrap powered isolated environment. This allows running graphical programs easy and doesn't require root privileges once installed.
 
[[Install]] the {{pkg|bubblewrap}} package.
 
Set up [[#Debian|Debian chroot]] at {{path|/var/chroots/debian}} and install necessary glibc applications using {{ic|apt-get}}.
 
Create an alias {{ic|glibc}} using bwrap in the Alpine Linux host to start applications from the [[#Debian|Debian chroot]].
 
{{cmd|$ alias glibc{{=}}"LANG{{=}}en_US.UTF-8 bwrap --bind /var/chroots/debian / --dev-bind /dev /dev --proc /proc --bind /sys /sys --bind /run /run --bind /home /home --ro-bind /etc/resolv.conf /etc/resolv.conf --ro-bind /etc/passwd /etc/passwd --ro-bind /etc/group /etc/group"}}
 
To run programs that use X11/Xorg you can use:
{{cmd|$ alias glibcX11{{=}}"LANG{{=}}en_US.UTF-8 bwrap --bind /var/chroots/debian / --dev-bind /dev /dev --proc /proc --bind /sys /sys --bind /run /run --bind /home /home --ro-bind /etc/resolv.conf /etc/resolv.conf --ro-bind /etc/passwd /etc/passwd --ro-bind /etc/group /etc/group --bind /tmp/.X11-unix/X0 /tmp/.X11-unix/X0 --setenv DISPLAY :0"}}
 
In this case you might need to use {{ic|xhost}} on the Alpine Linux host to allow local connections, e.g.:
{{cmd|# xhost + local:}}
 
Now we can invoke glibc-built binaries using the alias from the Alpine Linux host like so:
{{cmd|$ glibc ./binary}} or {{cmd|$ glibcX11 ./binary}}


On the '''linux-grsec''' kernel, you will need to relax chroot limitations:
When [[Wayland]] desktop like [[Sway]] runs without {{pkg|xwayland}} on the Alpine Linux host, electron apps like {{ic|vscode}}, {{ic|google-chrome}} etc needs to be started as follows:{{ic|<nowiki>$ glibc code --ozone-platform=wayland</nowiki>}}.


  sudo apk add debootstrap
== See also ==
  for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 0 | sudo tee $i; done
  mkdir ~/chroot
  sudo debootstrap --arch=i386 wheezy ~/chroot http://http.debian.net/debian/
  for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 1 | sudo tee $i; done
  sudo chroot ~/chroot /bin/bash


You can now use <code>apt-get</code> to install needed packages.
* [[Alpine Package Keeper]]
* [[Installing ArchLinux inside an Alpine chroot]]
* [[Compile software from source]]


[[Category:Package Manager]]
[[Category:Development]]
[[Category:Development]]
[[Category:Installation]]

Latest revision as of 23:55, 17 July 2025

This page documents various ways to manage software in Alpine Linux. Graphical software managers are available to supplement apk to manage official software packages along with Flatpaks.

This page also documents ways to run software compiled with glibc including graphical programs like Visual Studio Code, google-chrome, obsidian etc...

Alpine package keeper

The official package manager in Alpine Linux Alpine Package Keeper(apk) is a cli tool. Rosetta stone shows how standard package management tasks are done in Alpine Linux compared to other popular distributions.

Graphical software manager

The following graphical tools are available to manage software packages from official repositories and Flatpaks.

Gnome software

Gnome Software can be used as a GUI front end for apk for managing official software packages and flatpaks.

KDE Discover

KDE Discover can be used as a GUI front end for apk for managing official software packages and flatpaks.

Flatpak

Flatpak is by far the easiest method for running programs not available in the official Alpine Linux repositories. To use flatpaks, ensure that Flathub repository is enabled.

Running glibc programs

If you want to run glibc programs in Alpine Linux, there are a few ways of doing so.

For simpler binaries, you can install gcompat a compatibility layer or you could do it the easy way and use Flatpaks. See containers or chroot section for ways to run glibc programs including graphical ones.

gcompat

gcompat is a library which provides glibc-compatible APIs for use on musl libc systems like Alpine Linux. To install issue the command:

apk add gcompat

After that you run your binaries as normal.

For an usage example, refer Firefox page, where gcompat is used to run glibc compiled Widevine binary.

Chroot

An option that's easier to generalize to other glibc applications is installing a glibc-based distribution into a chroot. You can then either chroot into it, or use a symlink and some configuration to make its glibc (and associated libraries) usable from Alpine.

Tip: The most reliable way to enter a chroot is to use the start-chroot script.

After setting up a chroot using any of the methods described below, the loader can be set up in Alpine like so (these instructions are for a Debian chroot in /var/chroots/debian, on x86_64, but can be adapted to other systems by using the appropriate paths):

mkdir -p /lib64 ln -s /var/chroots/debian/lib/x86_64-linux-gnu/ld-2.33.so /lib64 printf '/var/chroots/debian/lib/x86_64-linux-gnu\n/var/chroots/debian/usr/lib/x86_64-linux-gnu\n' > /etc/ld.so.conf /var/chroots/debian/sbin/ldconfig

Gentoo Linux

Select a stage3 from here and portage latest from here at gentoo/snapshots/portage-latest.tar.xz.

First,

doas apk add xz

Enter the chroot:

mkdir ~/chroot cd ~/chroot tar -xvf stage3-*.tar.xz tar -xvf portage-latest.tar.xz mv portage usr doas mount --bind /dev dev doas mount --bind /sys sys doas mount -t proc proc proc cp /etc/resolv.conf etc doas chroot . /bin/bash

And voilà, you have your working Gentoo chroot!

You can now take a look at Gentoo's Handbook to find out how you can configure and install your system, or simply extract/copy the program you need to run in your chroot enviroment and execute it.

Here is a wrapper script that is similar to arch-chroot when you frequently reuse this chroot:

Also, create an account with the same user name as host current user to the chroot or make changes to the userspec option to chroot line.

Contents of gentoo-chroot.sh

!/bin/bash CHROOT_PATH="/home/$USER/chroot" cd $CHROOT_PATH mount | grep $CHROOT_PATH/dev || doas mount --bind /dev dev mount | grep $CHROOT_PATH/sys || doas mount --bind /sys sys mount | grep $CHROOT_PATH/proc || doas mount -t proc proc proc cp /etc/resolv.conf etc doas chroot --userspec=$USER:users . /bin/bash echo "You must manually unmount $CHROOT_PATH/dev, $CHROOT_PATH/sys, $CHROOT_PATH/proc."

Do at chmod +x gentoo-chroot.sh to get it to work.

Arch Linux

Either use pacstrap (included with the arch-install-scripts package) or an Arch bootstrap image:

doas apk add arch-install-scripts mkdir ~/chroot && cd ~/chroot curl -O https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.zst doas tar -x --zstd -f archlinux-bootstrap-x86_64.tar.zst && rm archlinux-bootstrap-x86_64.tar.zst doas sed -i '/evowise/s/^#//' root.x86_64/etc/pacman.d/mirrorlist doas sed -i '/CheckSpace/s/^/#/' root.x86_64/etc/pacman.conf doas arch-chroot root.x86_64 [chroot]# pacman-key --init [chroot]# pacman-key --populate archlinux

Once that is done, update the system and install the desired package(s) (denoted by "foo" in this example):

[chroot]# pacman -Syu foo

Debian

Alpine Linux provides debootstrap package to create the Debian chroot. Here are the steps:

# apk add debootstrap # mkdir -p /var/chroots/debian # debootstrap --arch amd64 stable /var/chroots/debian/ https://deb.debian.org/debian

The --arch is optional, depending on your needs.

For updating the Chroot or for installing applications i.e packages and their dependencies using apt-get, mount it and then login as root:

# mount --bind /dev /var/chroots/debian/dev # mount --bind /proc /var/chroots/debian/proc # mount --bind /dev/pts /var/chroots/debian/dev/pts # chroot /var/chroots/debian /bin/bash [chroot]# apt update && apt upgrade

After installing the necessary applications and what you might want to do, exit the chroot and umount the binds for /dev/pts, dev and proc to avoid issues.

# umount /var/chroots/debian/dev/pts # umount /var/chroots/debian/dev # umount /var/chroots/debian/proc

Containers

Distrobox + Podman

Distrobox combined with podman container running in rootless mode allows running glibc compiled graphical programs easy. This doesn't require root privileges once set up.

Bubblewrap + Chroot

A script glibc is used to create a container using Bubblewrap where a Debian chroot is the content of that container. It's not just a chroot anymore; it's a bubblewrap powered isolated environment. This allows running graphical programs easy and doesn't require root privileges once installed.

Install the bubblewrap package.

Set up Debian chroot at /var/chroots/debian and install necessary glibc applications using apt-get.

Create an alias glibc using bwrap in the Alpine Linux host to start applications from the Debian chroot.

$ alias glibc="LANG=en_US.UTF-8 bwrap --bind /var/chroots/debian / --dev-bind /dev /dev --proc /proc --bind /sys /sys --bind /run /run --bind /home /home --ro-bind /etc/resolv.conf /etc/resolv.conf --ro-bind /etc/passwd /etc/passwd --ro-bind /etc/group /etc/group"

To run programs that use X11/Xorg you can use:

$ alias glibcX11="LANG=en_US.UTF-8 bwrap --bind /var/chroots/debian / --dev-bind /dev /dev --proc /proc --bind /sys /sys --bind /run /run --bind /home /home --ro-bind /etc/resolv.conf /etc/resolv.conf --ro-bind /etc/passwd /etc/passwd --ro-bind /etc/group /etc/group --bind /tmp/.X11-unix/X0 /tmp/.X11-unix/X0 --setenv DISPLAY :0"

In this case you might need to use xhost on the Alpine Linux host to allow local connections, e.g.:

# xhost + local:

Now we can invoke glibc-built binaries using the alias from the Alpine Linux host like so:

$ glibc ./binary

or

$ glibcX11 ./binary

When Wayland desktop like Sway runs without xwayland on the Alpine Linux host, electron apps like vscode, google-chrome etc needs to be started as follows:$ glibc code --ozone-platform=wayland.

See also