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

Created on 25 Sep 2018  ·  35Comments  ·  Source: rbenv/ruby-build

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

Most helpful comment

@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

All 35 comments

Prior to updating to 10.14, everything worked without issue. Have uninstalled and reinstalled all Homebrew packages, updated all gems, tried gem pristine --all and so far am unable to get things installed.

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?

@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

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.

Does this problem happen if you create a new directory, rbenv init inside it, and then rbenv install 2.5.1? I just tried that both of my Mojave systems and it worked.

Also, another shot in the dark: Have you installed openssl with brew? I did at some point in the past since it's a common dependency. But maybe if openssl isn't installed, bad stuff happens?

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"

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.

Seeing this issue also, and the steps used by @ActionScripted unfortunately didn't help. This was on a completely fresh install of 10.14 (one of our build machines). Looks like we'll have to revert to 10.13 for now—I suspect this won't be the only build tool that needs some TLC for 10.14 support.

Fails to install on pristine Mojave, even when performing the steps described at https://github.com/rbenv/rbenv/issues/1122#issuecomment-424762699. Complains about clocked_t it seems:

process.c:7414:9: error: unknown type name 'clockid_t'; did you mean 'clock_id_t'?
        clockid_t c;
        ^~~~~~~~~
        clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int     clock_id_t;                     /* clock identification type */
                ^
process.c:7416:15: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        ret = clock_gettime(c, &ts);
              ^
process.c:7552:9: error: unknown type name 'clockid_t'; did you mean 'clock_id_t'?
        clockid_t c = NUM2CLOCKID(clk_id);
        ^~~~~~~~~
        clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int     clock_id_t;                     /* clock identification type */
                ^
process.c:7553:19: warning: implicit declaration of function 'clock_getres' is invalid in C99 [-Wimplicit-function-declaration]
        int ret = clock_getres(c, &ts);
                  ^
2 warnings and 2 errors generated.
make: *** [process.o] Error 1
make: *** Waiting for unfinished jobs....

@franklouwers Same issue from Sierra upgrade, solved by command-line tools reinstall: https://github.com/rbenv/ruby-build/issues/999#issuecomment-248936187

@jeremy doesn't work unfortunately (also note this is a fresh install, not an upgrade). Full log attached, cli output below:

~ ❯❯❯ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
~ ❯❯❯ clang -v
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
~ ❯❯❯ rbenv install 2.5.1
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/6s/wqp5xzwj04lc3tctjbjp22mm0000gn/T/ruby-build.20181003160422.82103
Results logged to /var/folders/6s/wqp5xzwj04lc3tctjbjp22mm0000gn/T/ruby-build.20181003160422.82103.log

Last 10 log lines:
        clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int     clock_id_t;                     /* clock identification type */
                ^
process.c:7553:19: warning: implicit declaration of function 'clock_getres' is invalid in C99 [-Wimplicit-function-declaration]
        int ret = clock_getres(c, &ts);
                  ^
2 warnings and 2 errors generated.
make: *** [process.o] Error 1
make: *** Waiting for unfinished jobs....

ruby-build.20181003160422.82103.log

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

Humm, My install worked fine ( Basically brand new to Ruby, so I know nothing )

For what it's worth, I was having a lot of issues installing 2.5.1 on Mojave today. None of the suggestions here worked, and I banged my head against the wall until I realized I needed to upgrade and migrate MacPorts, which I was using for something unrelated that completely broke my ruby builds.

For anyone experiencing build issues after trying everything here who is running MacPorts and who upgraded to Mojave, take a look at https://trac.macports.org/wiki/Migration

@franklouwers I'm experiencing the exact same issue. Deleting CommandLineTools doesn't solve this. Did you happen to find a solution?

Yeah, somehow (although this was a completely fresh install!!) an old version of the Xcode CLI tools found its way into my computer. I had (outdated) header files in /usr/include. After I removed them (which is a bit of a nuisance, because apple won't let you touch /usr by default, so you need to disable the security settings by rebooting into recovery mode etc), all went well.

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.

Thank you everyone for sharing your workarounds!

Note that having MacPorts installed on the system was known to break ruby-build in subtle ways even before Mojave. Please check your MacPorts installation if you're experiencing issues, and post build errors and related information at https://github.com/sstephenson/ruby-build/issues.

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 :)

@franklouwers so, the solution is? Remove macports? Move include folder? Or wait for the fix?

The solution for me was:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
rvm install 2.5.1

Works like a charm in MacOS High Sierra (updated in Macbook Pro 13" early 2011).

Thanks Allah I found this thread and read it calmly :). God bless you all guys. I almost cried because of rbenv failing for days. I kept going through the rabbit hole (as @franklouwers said) removed rvm, got rbenv, used CC=gcc8, CC=gcc6 and what not.

WHAT WORKED:
Following @junara I just renamed this directory /usr/local/include and rbenv install 2.2.2 worked perfect.

@franklouwers /usr/include is not the problem It has all necessary header files (_stdio.h, string.h in my case) where as /usr/local/include doesn't have these. I printed the search paths of header files by doing echo "#include " | gcc -v -x c - which showed following:

ignoring nonexistent directory "/usr/local/include" (because now it is /usr/local/includePROBLEM :)

include "..." search starts here:

include <...> search starts here:

/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include
/Library/Developer/CommandLineTools/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)

So it was looking into /usr/local/include first. When i looked into /usr/local/include directory, it didn't have string.h, any header file with underscore like _stdio.h etc.

@HasaanAli it was the problem in my case. I didn't even have /usr/local/include... If you install a clean Mojave and add XCode, you won't have /usr/include, unless you install an old version of XCode.

Why is this issue closed as its still an active problem?

@johncade Because it's an active problem with our macOS developer environments, not with rbenv itself. It's still a good place to discuss our workarounds and solutions to the macOS dev problems nonetheless. Though https://github.com/sstephenson/ruby-build/issues is a bit better, since ruby-build is the underlying tool that rbenv install uses. 😊

@ltankey Thanks friend, that helped a lot and solved my problem too! And yes it was indeed a 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. 👍

@samandmoore Just moving the directory worked for me. Thanks!

I had the same problem, this solution worked perfectly for me:

CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2r/ rbenv install 2.6.3

Use CONFIGURE_OPTS instead of RUBY_CONFIGURE_OPTS.

Regards, Thomas

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.

Was getting errors about not being able to "cross compile C programs", and needing to pass --host flags that only made matters worse.

But this comment worked for me: https://github.com/rbenv/rbenv/issues/1059#issuecomment-481750863

From @thegreyfellow:

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Complete installer, then run rbenv install ... as you usually would.

⚠️ Note: it looked like it was hanging a _looong_ time for me at ruby-build: use readline from homebrew, but finally went through. _Maybe try with a verbose flag?_

Just do sudo rvm install 2.5.1

I had openssl and [email protected] installed by Homebrew. Only [email protected] had dependent packages so I removed openssl and tried to install 2.6.4 with success.

Just use [email protected] and add the following settings in.bashrc or .zshrc:

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

You can have openssl 1.0.2t side by side with [email protected] but you need to add the above exports in your shell conf files.

Was this page helpful?
0 / 5 - 0 ratings