ruby-build: Unable to install Ruby 2.5.1 on macOS 10.14 Mojave

When running the following:

rbenv install 2.5.1

The install fails with the following output:

ruby-build: use openssl from homebrew
Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
Installing ruby-2.5.1...
ruby-build: use readline from homebrew

BUILD FAILED (OS X 10.14 using ruby-build 20180822)

Inspect or clean up the working tree at /var/folders/5g/f1t038j95cnf6xcvb783rl5hh80m9n/T/ruby-build.20180925130957.80594
Results logged to /var/folders/5g/f1t038j95cnf6xcvb783rl5hh80m9n/T/ruby-build.20180925130957.80594.log

Last 10 log lines:
Ignoring openssl-2.1.1 because its extensions are not built. Try: gem pristine openssl --version 2.1.1
ERROR: Ruby install aborted due to missing extensions
Configure options used:
  --prefix=/Users/mthompson/.local/share/rbenv/versions/2.5.1
  --with-openssl-dir=/usr/local/opt/openssl
  --with-readline-dir=/usr/local/opt/readline
  CC=clang
  CFLAGS= -O3 -Wno-error=shorten-64-to-32
  LDFLAGS=-L/Users/mthompson/.local/share/rbenv/versions/2.5.1/lib
  CPPFLAGS=-I/Users/mthompson/.local/share/rbenv/versions/2.5.1/include

Full log: https://gist.github.com/ActionScripted/526c7a85797fb0d05bb54000bc922d00

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 35 (3 by maintainers)

Most upvoted comments

@VivaLosDoyers thanks for the suggestion! I changed the developer directory from /Applications/Xcode.app/Contents/Developer to /Library/Developer/CommandLineTools and unfortunately it still isn’t working (same error/output as above).

Here’s what I tried:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

$ sudo xcode-select --switch /Library/Developer/CommandLineTools

$ xcode-select -p
/Library/Developer/CommandLineTools

Just do sudo rvm install 2.5.1

Found a fix, at least for me. I did a lot all at once and now things are working but I cannot discern which changes specifically fixed things. I believe this was an issue with some stale ruby/gem folders in /usr/local, ~/.local/share/rbenv, ~/.local/share/gem. (Note that my rbenv and gem paths are different because I prefer XDG Base Directory locations and I’m overriding things using environment variables.)

I removed the following:

brew uninstall rbenv ruby-build
rm -rf /usr/local/bin/{rdoc,ri,ruby}
rm -rf /usr/local/lib/ruby
rm -rf ~/.local/share/{gem,rbenv}

Then installed rbenv and tested:

brew install rbenv
eval "$(rbenv init -)"
rbenv install 2.5.1

And it works like a charm. The only thing that seems weird to me is that when I use Ruby 2.5.1 via rbenv global 2.5.1 my gem paths include references to 2.5.0:

$ rbenv versions
  system
* 2.5.1 (set by /Users/mthompson/.local/share/rbenv/version)
$ which ruby
/Users/mthompson/.local/share/rbenv/shims/ruby
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]
$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Users/mthompson/.local/share/gem
  - USER INSTALLATION DIRECTORY: /Users/mthompson/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/mthompson/.local/share/rbenv/versions/2.5.1/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/mthompson/.local/share/gem/bin
  - SPEC CACHE DIRECTORY: /Users/mthompson/.cache/gem
  - SYSTEM CONFIGURATION DIRECTORY: /Users/mthompson/.local/share/rbenv/versions/2.5.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /Users/mthompson/.local/share/gem
     - /Users/mthompson/.gem/ruby/2.5.0
     - /Users/mthompson/.local/share/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/mthompson/.local/share/rbenv/versions/2.5.1/bin
     - /usr/local/Cellar/rbenv/1.1.1/libexec
     - /Users/mthompson/.yarn/bin
     - /Users/mthompson/.local/share/rbenv/shims
     - /usr/local/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/sbin
     - /usr/local/opt/go/libexec/bin

Does it matter that the gem environment specifies paths to 2.5.0 while the Ruby version is 2.5.1? Everything seems to be working without issue, so maybe that’s not a problem?

At any rate, error on my end from having stale files/folders laying around after upgrading. Just needed to remove everything and start fresh and things work as expected.

After upgrading to 10.14, I encountered the similar error. Follow the comments below, I deleted ( = mv)/usr/local/include folder. And I succeeded in installing rbenv (like rbenv install 2.5.1 ).

https://github.com/rbenv/rbenv/issues/1059#issuecomment-420460206

Thanks @franklouwers you pointed in me in the right direction (what a nightmare!)

I followed this post which linked to these release notes which reference instructions about how command line tools now behave with respect to headers. It also provides a backup package (located at /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg) which can be installed to also get headers into /usr/include for software that doesn’t yet support using the Xcode SDK.

Digging around a bit, looks like there’s an issue building Ruby using RVM also: https://github.com/rvm/rvm/issues/4453

Might not be related, but there’s some great output there that might help. I’m thinking this is less rbenv/RVM and more something with building Ruby on 10.14. But I don’t know much about the internals of building Ruby.

Mislav, just to clarify (for other people that would end up at this page after a frustrating search-engine trip through the rabbit-hole): I did not have MacPorts installed, at any time the last 7 years on any of my macs. So the issue can pop up without having MacPorts installed as well! The key would be to check if you have a /usr/include directory. If you have, you have this issue 😃

After upgrading to 10.14, I encountered the similar error. Follow the comments below, I deleted ( = mv)/usr/local/include folder. And I succeeded in installing rbenv (like rbenv install 2.5.1 ).

#1059 (comment)

Thank you so much!! It worked for me. Thanks for ending this Terminal nightmare.

After upgrading to 10.14, I encountered the similar error. Follow the comments below, I deleted ( = mv)/usr/local/include folder. And I succeeded in installing rbenv (like rbenv install 2.5.1 ).

i followed this approach (using mv to be safe) and i was able to reinstall 2.3.1 and 2.4.2. 👍

With a clean brew, running brew install rbenv brings along: autoconf, openssl, pkg-config, ruby-build.

I removed everything from brew, ran brew install rbenv and then tried rbenv install 2.5.1 with the same result as before. Also tried rbenv init in a fresh folder and then the install with the same result.

I also tried both installs using the env vars from the brew openssl install output:

==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

FWIW I was able to install on a fresh Mojave installation on a 2012 MacBook Pro:

brew install rbenv rbenv install 2.5.1

It’s worth mentioning that my xcode-select is currently pointing at the command line tools, and not my Xcode installation. Perhaps that makes a difference?