rbenv / ruby-build

A tool to download, compile, and install Ruby on Unix-like systems.
https://rbenv.org/man/ruby-build.1
MIT License
3.89k stars 785 forks source link

Build of any Ruby fails on Arch Linux if system Ruby (3.2.4) is installed - `cannot load such file -- erb` #2435

Closed ZimbiX closed 3 months ago

ZimbiX commented 3 months ago

At least on Arch Linux, when system Ruby (3.2.4) is installed, building any version of Ruby fails with:

generating encdb.h
./tool/generic_erb.rb:6:in `require': cannot load such file -- erb (LoadError)
    from ./tool/generic_erb.rb:6:in `<main>'
make: *** [uncommon.mk:1261: encdb.h] Error 1

This took a fair while to debug - I had no idea that building Ruby would have anything to do with system Ruby! Thankfully, this comment from a very similar past issue clued me in: https://github.com/rbenv/ruby-build/issues/833#issuecomment-164148732.

Steps to reproduce the behaviour

I reproduced this in Docker to prove it's not caused by something about my individual setup, and for simpler reproduction.

With Dockerfile:

FROM archlinux@sha256:271083843fa6569f02dfc78b2bab94fce8d705c8aa9d581fc838437930ed977b

RUN pacman -Syu --noconfirm && \
  pacman -S --needed base-devel rust libffi libyaml openssl zlib --noconfirm && \
  pacman -S coreutils git --noconfirm

RUN git clone https://github.com/rbenv/rbenv /root/.rbenv && \
  git clone https://github.com/rbenv/ruby-build /root/.rbenv/plugins/ruby-build && \
  /root/.rbenv/bin/rbenv init
docker build .
docker run -it -v .:/work -w /work "$(docker build -q .)"

Running this in the presented Docker container fails:

. ~/.bash_profile
pacman -S ruby --noconfirm # install system ruby
rm -rf ~/.rbenv/versions/3.3.4
rbenv install 3.3.4

whereas this succeeds:

. ~/.bash_profile
pacman -Rs ruby --noconfirm || : # uninstall system ruby
rm -rf ~/.rbenv/versions/3.3.4
rbenv install 3.3.4

To be specific, I tried building these versions: 3.3.4, 3.2.0, 2.7.8, 2.7.6. They all fail in the same way.

Logs

ruby-build.20240819125035.247.log--failed-with-system-ruby-installed.txt ruby-build.20240819125300.35.log--succeeded-with-system-ruby-uninstalled.txt

[root@c847c81d3323 work]# rbenv --version
rbenv 1.3.0-3-gbf1fcd3
[root@c847c81d3323 work]# rbenv install --version
ruby-build 20240727-9-gd22fa95
➜ uname -a
Linux ZimbiX-ReadyTech-Linux 6.6.46-1-lts #1 SMP PREEMPT_DYNAMIC Wed, 14 Aug 2024 15:21:14 +0000 x86_64 GNU/Linux

Env in the container:

[root@16f941a68ef1 work]# env
HOSTNAME=16f941a68ef1
RBENV_SHELL=bash
PWD=/work
HOME=/root
LANG=C.UTF-8
TERM=xterm
SHLVL=1
PATH=/root/.rbenv/shims:/root/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/sbin/env

System Ruby:

[root@16f941a68ef1 work]# ruby --version
ruby 3.2.4 (2024-04-23 revision af471c0e01) [x86_64-linux]
hsbt commented 3 months ago

Can you try with pacman -S ruby-stdlib --noconfirm ? Archlinux extracted stdlib like erb from ruby package.

ZimbiX commented 3 months ago

Thanks! I didn't know that. Installing ruby-stdlib resolves the error (at least in the Docker example above).

However, I am still very confused why system Ruby matters at all. ruby-build compiles Ruby - why does that depend on Ruby (if installed)? That is rather surprising! And an unexpected, somewhat circular, dependency. Is this documented somewhere I missed? Cheers

hsbt commented 3 months ago

Yes, I'm also not sure why installer refer system ruby. The ruby package is not required base ruby. I investigate that.

PS. I'm also member of ruby core.

hsbt commented 3 months ago

I filed https://bugs.ruby-lang.org/issues/20687. So, this is not ruby-build issue. I'm closing this.