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

ruby-build is not always using the correct libyaml on OSX with Homebrew #1083

Closed sandrinr closed 5 years ago

sandrinr commented 7 years ago

On systems with multiple Homebrew instances, ruby-build will only use the libyaml installation in the default Homebrew installation location.

Steps to reproduce:

  1. Install Homebrew into the default location (/usr/local) and make sure that in this Homebrew instance libyaml is installed
  2. Install Homebrew additionally into a second location (anywhere) and make sure that libyaml, libffi, rbenv, and ruby-build are available in this Homebrew instance.
  3. Ensure your PATH in your current shell is set such that the bin directory of the second Homebrew instance is first on your PATH
  4. Use rbenv to install a newish Ruby version (e.g. 2.4.0).
  5. In the first instance of Homebrew (the one installed in the default location), remove the installation of libyaml (you will have to do that in another shell to ensure you are calling the correct brew)
  6. In irb of your installed Ruby version above run require "yaml"
  7. At this point you will get an error that Ruby is unable to load the libyaml library although it is installed in the Homebrew instance which contains the ruby-build version which built this version of Ruby

My preliminary analysis showed that ruby-build would have the infrastructure to do this the right way (i.e. use the --with-libyaml-dir configure option), contained in the function use_homebrew_yaml. However, it seems that this function is not used when compiling more recent versions of Ruby.

hsbt commented 7 years ago

Can you show the result of otool -L /path/to/your/psych.bundle ?

On systems with multiple Homebrew instances

It seems non-commonly environment, I think.

sandrinr commented 7 years ago

Below you can find the otool output.

$ otool -L /opt/origammi-toolchain/lamp-apache24-mysql57-php70-es17/homebrew/Cellar/rbenv/1.1.0/versions/2.4.0/lib/ruby/2.4.0/x86_64-darwin15/psych.bundle
/opt/origammi-toolchain/lamp-apache24-mysql57-php70-es17/homebrew/Cellar/rbenv/1.1.0/versions/2.4.0/lib/ruby/2.4.0/x86_64-darwin15/psych.bundle:
    /usr/local/opt/libyaml/lib/libyaml-0.2.dylib (compatibility version 3.0.0, current version 3.5.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

Here my expectation would be that otool would show the libyaml dependency to /opt/origammi-toolchain/lamp-apache24-mysql57-php70-es17/homebrew/opt/libyaml/lib/libyaml-0.2.dylib instead of the one in the default Homebrew location.

We use Homebrew to generate switchable web development toolchains which is not a "standard" application of Homebrew for sure. But a handy one :-).

My point is that ruby-build seems to have all the necessities in place but just does not use them for recent Ruby versions.

mislav commented 5 years ago

My preliminary analysis showed that ruby-build would have the infrastructure to do this the right way (i.e. use the --with-libyaml-dir configure option), contained in the function use_homebrew_yaml. However, it seems that this function is not used when compiling more recent versions of Ruby.

Correct (re: last point). To solve your libyaml issues, you should use RUBY_CONFIGURE_OPTS=--with-libyaml-dir=... explicitly.