praveen_coder
praveen_coder

Reputation: 303

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

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:

/Users/praveenk.k/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- openssl (LoadError) from /Users/praveenk.k/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in require'

Upvotes: 20

Views: 22676

Answers (7)

Dave
Dave

Reputation: 19090

On Mac OS X Big Sur, to install Ruby 2.3.2 with RVM, the fix was

brew install rbenv/tap/[email protected]
CFLAGS="-Wno-error=implicit-function-declaration" rvm reinstall ruby-2.2.5 --with-openssl-dir='/usr/local/opt/[email protected]'

Reference was here -- https://github.com/rvm/rvm/issues/4889

Upvotes: 1

Arsii Rasheed
Arsii Rasheed

Reputation: 351

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

Upvotes: 8

Ruan Nawe
Ruan Nawe

Reputation: 460

For me solve this in centos 7

$ openssl version -a


OpenSSL 1.0.2k-fips  26 Jan 2017
built on: reproducible build, date unspecified
platform: linux-x86_64
options:  bn(64,64) md2(int) rc4(8x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) 
compiler: gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM

------------------------------------------------------------------------
OPENSSLDIR: "/etc/pki/tls" <- ************* COPY THIS PATH *************
------------------------------------------------------------------------

engines:  rdrand dynamic 

paste the path in the bellow line how --with-openssl-dir param

$ RUBY_CONFIGURE_OPTS="--with-openssl-dir=/etc/pki/tls" rbenv install 2.7.2

Upvotes: 1

Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 13929

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

yum install openssl-devel

Upvotes: 0

cedric95fr
cedric95fr

Reputation: 121

For debian 10 :

sudo apt-get install -y libssl-dev

Upvotes: 12

Feuda
Feuda

Reputation: 2365

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

Upvotes: 28

David Bodow
David Bodow

Reputation: 717

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.

Upvotes: 17

Related Questions