ruby-build: Cannot install Ruby versions < 2.4 because of openssl@1.1 dependency

It seems the most recent change to ruby-build 20191002 homebrew formula to require openssl@1.1 breaks the install of Ruby versions that are < 2.4 (those require openssl 1.0.2q)

So, for macOS users who install ruby-build via homebrew, they will get openssl@1.1 installed as well.

If they then try to run rbenv install 2.1.10 for instance, it will fail with:

Last 10 log lines:
The Ruby openssl extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Configure options used:
  --prefix=/Users/username/.rbenv/versions/2.1.10
  --with-openssl-dir=/usr/local/opt/openssl@1.1
  --with-readline-dir=/usr/local/opt/readline
  CC=clang
  CFLAGS= -O3 -Wno-error=shorten-64-to-32 
  LDFLAGS=-L/Users/username/.rbenv/versions/2.1.10/lib 
  CPPFLAGS=-I/Users/username/.rbenv/versions/2.1.10/include 

Yeah, I know older versions are EOL but they still get used in some environments.

Seems like changing https://github.com/rbenv/ruby-build/blob/master/bin/ruby-build#L1023 to only check for openssl and not `openssl@1.1 could potentially fix this?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 31
  • Comments: 50 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@jyr There are multiple things wrong with what you are doing. First of all, you are using rvm, which is an entirely different tool for installing Ruby than this repo is (we are called “ruby-build”, also known as “rbenv install”).

Second, you clearly have OpenSSL 1.1 installed, and this whole thread is about Ruby 2.3 and lower not being compatible with OpenSSL 1.1. So your method of installation won’t work until you install OpenSSL 1.0 on your system.


To others: Homebrew-core has removed their openssl@1.0 formula due to OpenSSL 1.0 reaching end of life last month. This makes it harder to install Ruby 2.3 and older on macOS. You can try the following and see if it works:

brew install rbenv/tap/openssl@1.0
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.3.8

Since I helped move the 1.1 change along:

The workaround for EOL Ruby versions (or any that won’t build with 1.1) where you still want to use Homebrew is as follows: ~brew install openssl~ ~RUBY_CONFIGURE_OPTS=“–with-openssl-dir=/usr/local/opt/openssl” rbenv install 2.3.8~ Latest solution/workaround (March 2020): https://github.com/rbenv/ruby-build/issues/1353#issuecomment-573414540

(FWIW, the Homebrew formula was updated to use 1.1 at the end of August, the recent change was just to start looking for that version)

Thanks @mislav . One small tweak and it worked for me

brew --prefix openssl@1.0
export LDFLAGS="-L/usr/local/opt/openssl@1.0/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.0/include"
CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.3.8

I ran into this bug when trying to install Ruby 2.3.8 using the ASDF version manager. I was getting the following error when running:

asdf install ruby 2.3.8:

ERROR: Ruby install aborted due to missing extensions

Following the example above, I changed the command to the following and the installation worked correctly:

RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/opt/openssl" asdf install ruby 2.3.8

@12masta you have to install it first from the rbenv tap: brew install rbenv/tap/openssl@1.0

Inspired by this solution the following worked for me:

export optflags="-Wno-error=implicit-function-declaration"
rbenv install 2.1.2

Setting RUBY_CONFIGURE_OPTS or CFLAGS had no effect.

I had a similar problem. After unfortunately doing “brew upgrade” I ended up with openssl 1.1.1 installed and a bunch of broken already-installed rubies. To fix those up, I installed openssl@1.0 from the tap as explained by @gfguthrie and @mislav , then, to fix them all, executed the following commands in ~/.rbenv/versions:

$ find . -name \*.bundle -exec /bin/sh -c "file {} | grep -q Mach-O " \; -exec /bin/sh -c "objdump -macho -dylibs-used {} |grep -q libcrypto.1.0 " \; -exec sudo install_name_tool -change /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl@1.0/lib/libcrypto.dylib {} \;
AND
$ find . -name \*.bundle -exec /bin/sh -c "file {} | grep -q Mach-O " \; -exec /bin/sh -c "objdump -macho -dylibs-used {} |grep -q libssl.1.0 " \; -exec  sudo install_name_tool -change /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/opt/openssl@1.0/lib/libssl.dylib {} \;

Before executing this, you might want to print a list of the files you’re going to be working on:

find . -name \*.bundle -exec /bin/sh -c "file {} | grep -q Mach-O " \; -exec /bin/sh -c "objdump -macho -dylibs-used {} |grep -q libssl.1.0 " \; -print
AND
find . -name \*.bundle -exec /bin/sh -c "file {} | grep -q Mach-O " \; -exec /bin/sh -c "objdump -macho -dylibs-used {} |grep -q libcrypto.1.0 " \; -print

Since I helped move the 1.1 change along:

The workaround for EOL Ruby versions (or any that won’t build with 1.1) where you still want to use Homebrew is as follows:

brew install openssl
RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/opt/openssl" rbenv install 2.3.8

(FWIW, the Homebrew formula was updated to use 1.1 at the end of August, the recent change was just to start looking for that version)

This is very helpful, but frankly this should not have been a breaking change. Adding logic, or at least some kind of user feedback, would have been trivial in this case.

@burnettk what version of Command Line Tools do you have installed? You can check by running clang --version.

I suspect you may have version 12, which was just released by Apple on 9/16/2020. I can replicate a similar error installing 2.2.5 but I don’t have this error if I downgrade Command Line Tools to version 11.

@mislav Yes, that does work, thank you for providing that. I am able to install 2.3.8 with that fix.

I’m curious though why a plain rbenv install 2.3.8 that attempts to install its own version of openssl is failing. I should note that this is failing for me on all Ruby versions. For more recent versions, I have to set the options to point to Homebrew’s 1.1. I have not been successful with installing any Ruby version when rbenv attempts to install the openssl it needs. Does that make sense? Probably something on my machine and/or a separate issue.

These work

brew install rbenv/tap/openssl@1.0
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.3.8

brew install openssl
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" rbenv install 2.6.5

These don’t

rbenv install 2.3.8
rbenv install 2.6.5

I’m still getting this error…

$ RUBY_CONFIGURE_OPTS=“–with-openssl-dir=/usr/local/opt/openssl” rbenv install 1.9.3-p194 ruby-build: using libyaml from homebrew Downloading ruby-1.9.3-p194.tar.bz2… -> https://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.bz2 Installing ruby-1.9.3-p194…

WARNING: ruby-1.9.3-p194 is past its end of life and is now unsupported. It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew

BUILD FAILED (OS X 10.14.5 using ruby-build 20200224-6-gd8019fe)

Inspect or clean up the working tree at /var/folders/_w/98n31_kn03qfjt51p2hmrfqh0000gp/T/ruby-build.20200318004702.63722.sGWK6N Results logged to /var/folders/_w/98n31_kn03qfjt51p2hmrfqh0000gp/T/ruby-build.20200318004702.63722.log

Last 10 log lines: compiling regerror.c compiling regexec.c compiling regparse.c regparse.c:582:15: error: implicit conversion loses integer precision: ‘st_index_t’ (aka ‘unsigned long’) to ‘int’ [-Werror,-Wshorten-64-to-32] return t->num_entries; ~~~~~~ ~^~~~~~~~~ 1 error generated. make: *** [regparse.o] Error 1 make: *** Waiting for unfinished jobs… 13 warnings generated.

I can also confirm as @bfreezy suggested that command line tools 12 was the issue for me when trying to install 2.1.10. Downgrading to 11.5. fixed install issues for me and I ran install with RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.1.10 (On OS X 10.15.6) Also I found out before downgrading that there might issues and the command line tools are loaded from a wrong path as suggested below (I had wrong path for version 12 tools initially). https://github.com/rbenv/ruby-build/issues/1473#issuecomment-696765978

@hsbt Thanks for confirming that it’s possible to install. I tried uninstalling rbenv/tap/openssl@1.0 to simulate the exact install you did but unfortunately it still doesn’t work for me. I’m not sure what I could be doing differently here. Do you have any advice or recommendations on what I could try?

$ rbenv install 1.9.3-p551
Downloading openssl-1.0.2u.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16
Installing openssl-1.0.2u...
Installed openssl-1.0.2u to /Users/mamuller/.rbenv/versions/1.9.3-p551

ruby-build: using libyaml from homebrew
Downloading ruby-1.9.3-p551.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p551.tar.bz2
Installing ruby-1.9.3-p551...

WARNING: ruby-1.9.3-p551 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew

BUILD FAILED (Mac OS X 10.15.6 using ruby-build 20200727)

Inspect or clean up the working tree at /var/folders/65/8ndfq5g12c3bw1ktst21pfs4rn2nnt/T/ruby-build.20200818180658.99119.LK2wsN
Results logged to /var/folders/65/8ndfq5g12c3bw1ktst21pfs4rn2nnt/T/ruby-build.20200818180658.99119.log

Last 10 log lines:
make[2]: *** [ossl_pkcs7.o] Error 1
make[1]: *** [ext/openssl/all] Error 2
make[1]: *** Waiting for unfinished jobs....
installing default nkf libraries
linking shared-object nkf.bundle
ld: warning: directory not found for option '-L/Users/mamuller/.rbenv/versions/1.9.3-p551/lib'
17 warnings generated.
linking shared-object date_core.bundle
ld: warning: directory not found for option '-L/Users/mamuller/.rbenv/versions/1.9.3-p551/lib'
make: *** [build-ext] Error 2

For anyone other MacOS users and Swift lang users where

RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" rbenv install 2.6.5

doesn’t work. Check and see if your global environment is using the system Swift lang or a Toolchain build. Setting swiftenv global system did the trick.

export optflags="-Wno-error=implicit-function-declaration"
rbenv install 2.1.2

I am installing 2.3.4 and it’s showing me openssl error shown below. (I have macos 11.5.1 and xcode 12.0.5) image

I had an exactly same issue. When I ran rbenv install 2.3.3, I had this error:

Last 10 log lines:
The Ruby openssl extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Configure options used:
  --prefix=/Users/username/.rbenv/versions/2.3.3
  --with-openssl-dir=/usr/local/opt/openssl@1.1
  --with-readline-dir=/usr/local/opt/readline
  CC=clang
  CFLAGS= -O3 -Wno-error=shorten-64-to-32 
  LDFLAGS=-L/Users/username/.rbenv/versions/2.3.3/lib 
  CPPFLAGS=-I/Users/username/.rbenv/versions/2.3.3/include 

From the post by @bfreezy, I learned that the version of Command Line Tools should not be 12. (Thank you so much for the information!) In fact, this is what I had

$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.2)

Therefore, I downgraded my Commond Line Tools version to 11 by following this post and I confirmed the version is downgraded.

$ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)

Now I expect that rbenv install 2.3.3 will work, but it still failed with the following error. (--verbose just logs additional details)

$ rbenv install 2.3.3 --verbose
...
Downloading openssl-1.0.2u.tar.gz...
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/bin/curl
  Reason: image not found
/usr/local/bin/ruby-build: line 337:  3227 Abort trap: 6           curl -qsILf ${CURL_OPTS} "$1" 1>&4 2>&1
...
error: failed to download openssl-1.0.2u.tar.gz

BUILD FAILED (Mac OS X 10.15.6 using ruby-build 20201005)

It seems like there is an issue with curl, so I tried to reinstall it with the following command.

$ brew install --force curl
Updating Homebrew...
Warning: curl 7.72.0 is already installed, it's just not linked
You can use `brew link curl` to link this version.

As you can see above, in my case, I already had the latest version installed, but it was not linked. Therefore, I updated the path of the curl like below

$ export PATH="/usr/local/opt/curl/bin:$PATH"

And tried rbenv install 2.3.3 again and it worked!! Hope it helps!!

@jyr There are multiple things wrong with what you are doing. First of all, you are using rvm, which is an entirely different tool for installing Ruby than this repo is (we are called “ruby-build”, also known as “rbenv install”).

Second, you clearly have OpenSSL 1.1 installed, and this whole thread is about Ruby 2.3 and lower not being compatible with OpenSSL 1.1. So your method of installation won’t work until you install OpenSSL 1.0 on your system.

To others: Homebrew-core has removed their openssl@1.0 formula due to OpenSSL 1.0 reaching end of life last month. This makes it harder to install Ruby 2.3 and older on macOS. You can try the following and see if it works:

brew install rbenv/tap/openssl@1.0
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.3.8

AND does this work for ruby 1.9.3-p194 ??? Or ANY ruby under 2.0???

That workaround from an older comment was stale. It will not work for any older Ruby versions.

The new workaround for installing Ruby 2.3 and older on macOS is in my own comment above: #1353 (comment)

This seems to have worked for me! THANK YOU @mislav

@hardvain you probably don’t need to pass the option at all. 2.3.7 I don’t think will work with 1.1, and from the error it looks like you don’t have anything in /usr/local/opt/openssl. If you don’t pass in anything, ruby-build (assuming you have the current version) will just install the openssl that is needed for 2.3.7.