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

Solution 1:

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

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

For debian 10 :

sudo apt-get install -y libssl-dev

Solution 4:

On mac BigSur, I fixed it via

$ rvm pkg install openssl
$ rvm install 2.1.2 -C --with-openssl-dir=$HOME/.rvm/usr

or you can also try with

$ rvm pkg install openssl
$ CFLAGS="-Wno-error=implicit-function-declaration" rvm install 2.1.2 -C --with-openssl-dir=$HOME/.rvm/usr