6

I installed rbenv and tried to install ruby 1.9.3 on Debian 9 as instructed here https://github.com/rbenv/ruby-build/wiki

OpenSSL bindings on Debian
Because of OpenSSL incompatibility in Debian (7.5 and above), Ruby might fail to compile without patching it first:

curl -fsSL https://github.com/ruby/ruby/commit/1e7a929c1d44d7a368fbe379211183ac6c972920.patch | \
rbenv install --patch 1.9.3-p484

and the response I got was

Installing ruby-1.9.3-p484...
patching file ChangeLog
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file ChangeLog.rej
patching file ext/openssl/ossl_ssl.c
Hunk #1 succeeded at 1985 (offset -244 lines).

BUILD FAILED (Debian 9.4 using ruby-build 20160913)

Well, the changes in ChangeLog are not needed for ruby to work, or course. Then I found this https://github.com/mathbruyen/computers/blob/master/computers/AspireOne.md

curl -fsSL https://github.com/ruby/ruby/commit/1e7a929c1d44d7a368fbe379211183ac6c972920.patch | filterdiff --strip=1 -i a/ext/openssl/ossl_ssl.c | rbenv install -p 1.9.3-p484

from which I was able to find a way to apply only the hunk for OpenSSL related file. Filterdiff can be installed on Debian: apt install patchutils .
Result of installing Ruby 1.9.3-p484

BUILD FAILED (Debian 9.4 using ruby-build 20160913)

Inspect or clean up the working tree at /tmp/ruby-build.4890
Results logged to /tmp/ruby-build.4890.log

Last 10 log lines:
     ossl_ssl_def_const(OP_ALL);
     ^~~~~~~~~~~~~~~~~~
Makefile:269: recipe for target 'ossl_ssl.o' failed
make[2]: *** [ossl_ssl.o] Error 1
make[2]: Leaving directory '/tmp/ruby-build.4890/ruby-1.9.3-p484/ext/openssl'
exts.mk:126: recipe for target 'ext/openssl/all' failed
make[1]: *** [ext/openssl/all] Error 2
make[1]: Leaving directory '/tmp/ruby-build.4890/ruby-1.9.3-p484'
uncommon.mk:178: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2

Now I noticed there still is a an openssl related error. So I tried another libssl-dev-package:

sudo apt install libssl-dev

Now installing ruby 1.9.3-p484 was without errors, great!! But even though the installation was now without errors, openssl is still not available in ruby.

user@debian:~$ rbenv rehash
user@debian:~$ rbenv versions
  system
  1.9.3-p484
user@debian:~$ rbenv local 1.9.3-p484
user@debian:~$ irb
irb(main):001:0> require 'openssl'
LoadError: cannot load such file -- openssl
        from /home/user/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/user/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from (irb):1
        from /home/user/.rbenv/versions/1.9.3-p484/bin/irb:12:in `<main>'
irb(main):002:0>

EDIT: For ruby 1.9.3-p484 it says in the log:

Failed to configure openssl. It will not be installed.

That's why installation was successful, but openssl was not working. Looking for the word 'error' in the logs I also found " error: ‘SSLv3_method’ undeclared", which was fixed in a separate patch.

The Wiki additionally says all the following:

The openssl extension of Ruby version before 2.4 is not compatible with OpenSSL 1.1.x. At the moment, most Linux distributions that come with OpenSSL 1.1.0 have a separate package for OpenSSL 1.0.x.

On Debian 9 (stretch), it is libssl1.0-dev (note installing this would remove libssl-dev).

and

OpenSSL “SSLv3_method undeclared” error
For older Ruby versions like 1.9.3 the above patch will not work, use this instead:

curl -fsSL https://gist.github.com/FiveYellowMice/c50490693d47577cfe7e6ac9fc3bf6cf.txt | \
 rbenv install --patch 1.9.3-p551

So, in my setup the valid steps are:
1. sudo apt install libssl1.0-dev
2. curl -fsSL https://gist.github.com/FiveYellowMice/c50490693d47577cfe7e6ac9fc3bf6cf.txt | rbenv install --patch 1.9.3-p551

Now it works fine:

user@debian:~$ rbenv rehash
user@debian:~$ rbenv versions
  system
* 1.9.3-p484 (set by /home/user/.ruby-version)
  1.9.3-p551
user@debian:~$ rbenv local 1.9.3-p551
user@debian:~$ irb
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0>

Hopefully this would help someone!

tujuni
  • 96
  • 8

0 Answers0