Install Homebrew on Alpine Linux
There is a wiki page with the same title as this article in the original Linuxbrew repository (now merged into Homebrew)1, but the information there is slightly out of date. So here is a more up-to-date version.
You can start Alpine Linux with the alpine Docker image:
docker run -it --rm alpine:latest sh
Prepare dependencies
apk add bash curl git libc6-compat sudo sed -i -- '1a\ case $1 in --version)\ echo "ldd 2.16"\ exit\ esac' /usr/bin/ldd ln -s /bin/stat /usr/bin/stat
Homebrew now can automatically download and install Potable Ruby, so we don't need to install Ruby from the package manager.
Potable Ruby depends on glibc, and Alpine Linux uses musl libc, so we need to install the libc6-compat package. On
newer versions of Alpine Linux, libc6-compat is an alias for gcompat.
The installation script would use ldd to check the glibc version, so we use sed to patch the ldd script.
The installation script uses /usr/bin/stat, but Alpine Linux only has /bin/stat, so we create a symlink.
Add a normal user
Add a normal user, add it to the wheel group, and allow it to use sudo. Homebrew do not allow running as root, so we
need a normal user.
adduser tom adduser tom wheel echo '%wheel ALL=(ALL:ALL) ALL' > /etc/sudoers.d/99-custom su -l tom
Dwonload the installation script and run it
wget https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh bash install.sh
Post-installation
Try running some commands and install some packages.
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv sh)" brew doctor brew install hello hello
NOTE:
brew shellenvwithout arguments will failed, because it needspsto support-poption, which is not supported by busybox. You can use likebrew shellenv shto declare the shell type explicitly, or installprocps-ngpackage.brew listwill fail, because it needslsto support-qoption, which is not supported by busybox2. You can installcoreutilspackage, or use the patched ls script to replace/bin/ls.- the uninstallation script will fail, because it needs
findto support-lnamefilter, which is not supported by busybox. You can installfindutilspackage to fix this.
-
busybox added
ls -qsupport recently, but it is not available for Alpine Linux right now. ↩