Installing ruby-2.1.2: Cannot load such file — openssl (LoadError)

MacOS

Question or issue on macOS:

Getting few errors while installing ruby-2.1.2 using rvm. I am new to ruby and hence need assistance. Please let me know

Installation log and other relevant information here: log

From the log provided in problem description, I have ruby 2.1.2 installed in the system. However, getting error when tried listing gems with gem list due to installation errors.After changing to 2.1.2 i.e., rvm use 2.1.2 and executing ruby -r openssl -e ‘puts OpensSSL::OPENSSL_VERSION’ gives this error:

How to solve this problem?

Solution no. 1:

Ruby <2.4 is incompatible with OpenSSL 1.1 (e.g see https://github.com/rbenv/ruby-build/issues/1353).

Just a hunch, but if you’re using Mac + Homebrew, OpenSSL 1.0 was recently deleted, so anything along the lines of brew upgrade openssl would trash that.

There are several options to deal with this:

  1. I have older Rubies via asdf installed with LibreSSL (which may be safer anyway, see https://security.stackexchange.com/questions/112545/what-are-the-main-advantages-of-using-libressl-in-favor-of-openssl):
$ openssl
OpenSSL> version
LibreSSL 2.8.3
  1. Compile and link your own OpenSSL 1.0 (or then set compiler flags as environment variables when building Ruby — https://rvm.io/rubies/installing)
  2. See if your system’s package manager allows you to access openssl 1.0 and install with that (was helping a coworker with this recently and we weren’t able to find a good keg for homebrew at this time, unfortunately)

There might be something less convoluted than that; if someone has ideas, please feel free to comment or give an alternate answer.

EDIT

I personally ran into this issue with some other software and discovered that this fixed it, since the old SSL version was sitting around still:

brew switch openssl 1.0.2s

Should work so long as Homebrew doesn’t “helpfully” clean that out for me.

Solution no. 2:

Worked example

brew install rbenv/tap/[email protected]
rvm install 2.1.2 -C --with-openssl-dir=`brew --prefix [email protected]`

It’s from https://github.com/rvm/rvm/issues/4819#issuecomment-595644550

Solution no. 3:

For debian 10 :

sudo apt-get install -y libssl-dev

Solution no. 4:

On Amazon Linux 2, even if openssl is installed, you need the full dev kit

yum install openssl-devel

Hope this helps!