2

Ruby comes up with LoadErrors I do not understand. It complains about opening a shared object file, while it's present.

irb(main):001:0> require 'openssl'
LoadError: libssl.so.1.0.0: cannot open shared object file: No such file or directory - /usr/lib/ruby/2.3.0/x86_64-linux/openssl.so
    from /usr/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/openssl.rb:13:in `<top (required)>'
    from /usr/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

but ls /usr/lib/ruby/2.3.0/x86_64-linux/openssl.so
returns the file /usr/lib/ruby/2.3.0/x86_64-linux/openssl.so

Load Path:

irb(main):001:0> pp $LOAD_PATH
["/usr/lib/ruby/site_ruby/2.3.0",
 "/usr/lib/ruby/site_ruby/2.3.0/x86_64-linux",
 "/usr/lib/ruby/site_ruby",
 "/usr/lib/ruby/vendor_ruby/2.3.0",
 "/usr/lib/ruby/vendor_ruby/2.3.0/x86_64-linux",
 "/usr/lib/ruby/vendor_ruby",
 "/usr/lib/ruby/2.3.0",
 "/usr/lib/ruby/2.3.0/x86_64-linux"]

Another example, with the rails gem installed, generating a new project fails with following LoadError.

/usr/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:120:in `require': libcrypto.so.1.0.0: cannot open shared object file: No such file or directory - /usr/lib/ruby/2.3.0/x86_64-linux/digest/md5.so (LoadError)

And again, doing ls /usr/lib/ruby/2.3.0/x86_64-linux/digest/md5.so shows the presence of the file.

my ruby version is ruby 2.3.1p112. In case you wonder, uname -m returns x86_64.

I must miss something obvious, I guess. Any hints popping up are much appreciated!

arminfro
  • 1,303
  • 11
  • 14
  • 2
    Run `ldd /usr/lib/ruby/2.3.0/x86_64-linux/openssl.so`. You are probably missing libraries that the shared objects are linked against. – jordanm Jul 04 '18 at 02:36
  • Thank you for your comment jordanm, that pointed me in the right direction :) – arminfro Jul 04 '18 at 07:26
  • Possible duplicate of https://stackoverflow.com/q/65000467/12544391, e.g. adding `gem "ffi"` to `Gemfile` fixes it – Dorian Aug 23 '21 at 17:11

1 Answers1

5

Thanks to jordanm's comment, I was able to solve the issue!

The issue was related to openssl. ldd prints shared object dependencies and revealed the missing libraries.

ldd /usr/lib/ruby/2.3.0/x86_64-linux/openssl.so
...
libssl.so.1.0.0 => not found
libcrypto.so.1.0.0 => not found
...

After installing openssl-1.0 package, (while openssl v1.1.0 package was installed), the output of the same command looks better:

libssl.so.1.0.0 => /usr/lib/libssl.so.1.0.0 (0x00007faddac8f000)
libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007fadda814000)

and now, I'm able to require 'openssl' as well as generating a new rails project.

But after all, shouldn't ruby complain about missing packages, or should openssl-1.0 be at least a dependency of rails?

arminfro
  • 1,303
  • 11
  • 14
  • 1
    Gem dependencies can not expressly depend on system packages/libraries, but they will fail to compile in cases when the relevant system libraries don't exist. I suspect that openssl was installed when you setup the ruby environment but was removed later. – jordanm Jul 04 '18 at 18:21
  • You're right, I was cleaning up my system and removed some packages. `openssl-1.0` was properly removed, as a dependency of a package I removed. Thanks for the explanation :) – arminfro Jul 05 '18 at 09:05