Skip to content

Instantly share code, notes, and snippets.

@yob
Last active May 21, 2024 10:37
Show Gist options
  • Save yob/08d53a003181aa0fcce9812b1b533870 to your computer and use it in GitHub Desktop.
Save yob/08d53a003181aa0fcce9812b1b533870 to your computer and use it in GitHub Desktop.
Installing ruby 3.0 with rbenv/ruby-build with openssl 3

Bllergh. This is a real pain.

The openssl extension that ships with ruby 3.0 only compiles against openssl <= 1.1, but now openssl 3.0 is shipped in debian testing/unstable.

Ruby bug here: https://bugs.ruby-lang.org/issues/18658

Version >= 3.0 of the openssl rubygem does compile against openssl 3.0 though.

I use rbenv to manage ruby versions on my system, which uses ruby-build to manage installs.

I really don't want to compile or install a parallel openssl version, so I used a version of the process suggested by mame in the ruby bug to workaround the issue.

tl;dr trick rbenv/ruby-build into installing ruby without openssl, manually download the openssl 3.0 gem using not-ruby and install it.

Modify ruby-build to skip checking for openssl ($HOME/.rbenv/plugins/ruby-buildbin/ruby-build):

diff --git a/bin/ruby-build b/bin/ruby-build
index ccfe468..b729b29 100755
--- a/bin/ruby-build
+++ b/bin/ruby-build
@@ -1141,7 +1141,7 @@ build_package_verify_openssl() {
       )
     }
 
-    failed = %w[openssl readline zlib yaml].reject do |lib|
+    failed = %w[readline zlib yaml].reject do |lib|
       begin
         require lib
       rescue LoadError

Install ruby 3.0:

$ RUBY_CONFIGURE_OPTS="--without-openssl" rbenv install 3.0.4

Download and install version of the openssl gem that compiles against openssl 3.0:

$ wget https://rubygems.org/downloads/openssl-3.0.0.gem
$ rbenv shell 3.0.4
$ gem install openssl-3.0.0.gem

Test the manually installed gem works by installing a new gem that needs to be downloaded over https:

$ gem install pdf-reader
Fetching pdf-reader-2.10.0.gem
Fetching ruby-rc4-0.1.5.gem
Fetching hashery-2.1.2.gem
Fetching Ascii85-1.1.0.gem
Fetching ttfunk-1.7.0.gem
Fetching afm-0.2.2.gem
Successfully installed ttfunk-1.7.0
Successfully installed ruby-rc4-0.1.5
Successfully installed hashery-2.1.2
Successfully installed Ascii85-1.1.0
Successfully installed afm-0.2.2
Successfully installed pdf-reader-2.10.0
Parsing documentation for ttfunk-1.7.0
Installing ri documentation for ttfunk-1.7.0
Parsing documentation for ruby-rc4-0.1.5
Installing ri documentation for ruby-rc4-0.1.5
Parsing documentation for hashery-2.1.2
Installing ri documentation for hashery-2.1.2
Parsing documentation for Ascii85-1.1.0
Installing ri documentation for Ascii85-1.1.0
Parsing documentation for afm-0.2.2
Installing ri documentation for afm-0.2.2
Parsing documentation for pdf-reader-2.10.0
Installing ri documentation for pdf-reader-2.10.0
Done installing documentation for ttfunk, ruby-rc4, hashery, Ascii85, afm, pdf-reader after 2 seconds
6 gems installed

@plaindocs
Copy link

@JuanitoFatas thanks for this! ;-)

@akostadinov
Copy link

akostadinov commented Oct 13, 2022

@JuanitoFatas fixed it, but what's gonna happen when you link to openssl 1.1.1 and your database driver which is linked with 3.x?

To install

  • I applied the patch as listed above (to /home/myuser/.asdf/plugins/ruby/ruby-build/bin/ruby-build as I use asdf-vm)
  • to build
RUBY_CONFIGURE_OPTS="--without-openssl --with-openssl-dir=/usr" asdf install ruby 3.0.4

--with-openssl-dir is needed to prevent openssl 1.1.1q to be installed separately.

  • finally followed openssl gem installation instructions above

Just FYI, if I install ruby 3.0.4 without hacks, it installs openssl 1.1.1q and links openssl 2.x gem with it. Then even if I install openssl 3.x gem, it is also linked to that openssl 1.1.1q lib. That's why I had to through the extra hoops. I think proper solution would be to just allow an environment variable to control which version of openssl gem will be installed with ruby 3.0 so that this is internally handled by ruby-build.

P.S. for Ruby 2.7.8 I had to:

  • use RUBY_CONFIGURE_OPTS="--without-openssl --with-openssl-dir=/usr --with-ext=psych,+" asdf install ruby 2.7.8
  • cd /tmp/ruby-build.###########/ruby-2.7.8/
  • vi lib/rubygems/specification.rb comment out references to openssl and OpenSSL
  • make install
  • asdf reshim ruby 2.7.8
    Now we need to install a newer openssl gem but first have to replace rubygems, otherwise that would be impossible
  • cd ~/.asdf/installs/ruby/2.7.8/
  • rm -r ./lib/ruby/2.7.0/rubygems*
  • cheated by copying over from another ruby installation: cp -a ../3.2.2/lib/ruby/3.2.0/rubygems
  • cd elsewhere_where_2.7.8_will_be_default_ruby
  • download openssl gem from rubygems.org
  • gem install /tmp/openssl-3.2.0.gem --backtrace
  • install openssl also as a default gem: cd ~/.asdf/installs/ruby/2.7.8/
    • cp -a lib/ruby/gems/2.7.0/gems/openssl-3.2.0/lib/openssl* lib/ruby/2.7.0/
    • mv -i lib/ruby/2.7.0/openssl.so lib/ruby/2.7.0/x86_64-linux/

@swebb
Copy link

swebb commented Dec 20, 2022

I think there is a missing forward slash between ruby-build and bin:

$HOME/.rbenv/plugins/ruby-buildbin/ruby-build

should be:

$HOME/.rbenv/plugins/ruby-build/bin/ruby-build

@tushar-mittal
Copy link

this worked for me!! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment