What is the correct way to install ruby on ubuntu 22.04
Asked Answered
E

5

14

There is an issue with installing ruby on ubuntu 22.04 with rvm as it will give you error below enter image description here

Error running '__rvm_make -j8',
please read /usr/share/rvm/log/1655413907_ruby-2.5.0/make.log

There has been an error while running make. Halting the installation.

The same error if I try to install ruby 2.7.0, 2.7.1. 2.7.2 and higher.

I have found the suggestion here to use the following steps

rvm pkg install openssl

rvm remove x.x.x

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

This makes installation successful but then some libraries like pg or rails or puma do not work with ruby version that was installed this way. For example after bundle install if you run command 'rails db:migrate' it will give you another error from pg gem - Segmentation fault

/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record.rb:113: [BUG] Segmentation fault at 0x00007f03df83e140
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0011 p:0009 s:0055 e:000053 METHOD /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb:53
c:0010 p:0014 s:0047 e:000046 METHOD /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb:18
c:0009 p:0039 s:0042 e:000041 METHOD /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record.rb:100
c:0008 p:0070 s:0034 e:000033 METHOD /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record.rb:68
c:0007 p:0009 s:0028 e:000027 BLOCK  /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:76
c:0006 p:0017 s:0025 e:000024 METHOD /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:103
c:0005 p:0008 s:0018 e:000017 BLOCK  /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:76 [FINISH]
c:0004 p:---- s:0014 e:000013 CFUNC  :each
c:0003 p:0011 s:0010 e:000009 BLOCK  /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:75 [FINISH]
c:0002 p:0007 s:0006 e:000005 BLOCK  /usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/internals/thread_pool.rb:6 [FINISH]
c:0001 p:---- s:0003 e:000002 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/internals/thread_pool.rb:6:in `block in add'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:75:in `block in start'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:75:in `each'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:76:in `block (2 levels) in start'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:103:in `_timed'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/adapter/base.rb:76:in `block (3 levels) in start'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record.rb:67:in `build'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record.rb:102:in `_fast_build_dir'
/usr/share/rvm/gems/ruby-2.5.0/gems/listen-3.1.5/lib/listen/record/entry.rb:18:in `children'

-- Machine register context ------------------------------------------------
 RIP: 0x00007f03df83e140 RBP: 0x000055e2c1faa3e8 RSP: 0x00007ffcb2ab4718
 RAX: 0x0000000000000000 RBX: 0x00007f03df8412c0 RCX: 0x0000000000000000
 RDX: 0x000055e2bc30f010 RDI: 0x000055e2c1faa6c0 RSI: 0x000055e2c260c540
  R8: 0x0000000000000000  R9: 0x0000000000000000 R10: 0x00007f03dff62630
 R11: 0x00007f03e0076890 R12: 0x000055e2c1faa3e0 R13: 0x00007f03dfd83b10
 R14: 0x0000000000000000 R15: 0x000055e2c2670fd0 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
Unexpected size of .debug_line in /usr/share/rvm/rubies/ruby-2.5.0/bin/ruby
/usr/share/rvm/rubies/ruby-2.5.0/lib/libruby.so.2.5(rb_vm_bugreport+0x4ae) [0x7f03e16b18ce]
/usr/share/rvm/rubies/ruby-2.5.0/lib/libruby.so.2.5(0xaafbd) [0x7f03e152ffbd]
/usr/share/rvm/rubies/ruby-2.5.0/lib/libruby.so.2.5(0x19e2e6) [0x7f03e16232e6]
/lib/x86_64-linux-gnu/libc.so.6(0x7f03e128e520) [0x7f03e128e520]
/lib/x86_64-linux-gnu/libssl.so.3(0x7f03df83e140) [0x7f03df83e140]

According to this postenter link description here this issue with pg gem is also releted to openssl version

So both of these issues are related to OpenSSL version that comes with ubuntu 22.04 but I cannot find any guide that explains step-by-step how to fix it or how to use the older OpenSSL version for ruby installation that will work without all these errors.

So what are the correct steps to install ruby on Ubuntu 22.04?

Eutectoid answered 16/6, 2022 at 21:55 Comment(2)
you are correct, few weeks ago i had same problem as you with openssl. i had to downgrade ubuntu to 20.04Ellmyer
I am on the very same page here and honestly, downgrading doesn't look a bad option atm.Thorndike
O
9

What works for me is to run

rvm pkg install openssl

and then

rvm install ruby-2.7.3 --with-openssl-dir=$HOME/.rvm/usr

Overtone answered 31/8, 2022 at 0:55 Comment(2)
Warning: even if Ruby compiles with it, some gems will not work! Especially MySQL gem, that compiles with OpenSSL 3 and binary incompabilte with RVM's own OpenSSL 1.0Ionogen
@marco8757, Thanks It work for me to install ruby versions in ubuntu 22.04Crumley
C
7

Most people who arrive here from Google are likely running the following:

rvm install ruby

As of writing, this will install ruby 3.0.0 which will give you a build error on Ubuntu 22.04.

Most people probably want to install the latest 3.1.0, which does not show when running rvm list known.

To install the latest (which is currently 3.1.0) run:

rvm install ruby-3.1.0

The latest will install fine on Ubuntu 22.04.

Collis answered 17/11, 2022 at 2:12 Comment(2)
Thank you for the rvm specific answer!Footlight
Will try it, thanks! All other methods are failing for me because even if Ruby does install, Rails application goes into segfault as MySQL uses newer SSL library.Ionogen
B
5

I had the same problem, and the best solution was to use the rbenv instead of rvm. You won't need to downgrade the openssl version of Ubuntu 22.04, because the rbenv already download and use the openssl 1.1.1 for your ruby version.

Install rbenv https://github.com/rbenv/rbenv with ruby-build as plugin https://github.com/rbenv/ruby-build

My versions (Openssl, Ruby and Rbenv) enter image description here

Boorer answered 10/7, 2022 at 22:53 Comment(0)
T
3

After following pretty much what you went though, I was at the point of considering to downgrade the whole system. Luckily, i found this article

https://deanpcmad.com/2022/installing-older-ruby-versions-on-ubuntu-22-04/

And decided to give it one last chance. Author is using there tool called asdf, but there is a note, that same configuration should work with rbenv. I run rvm implode, installed rbenv, installed gems and started rails server.

And it worked! Not sure what is wrong with rvm, wither it is its fault or OpenSSL mismatch, but currently I want to focus on coding and that's it.

Hope that will help somebody to make further research.

Thorndike answered 7/7, 2022 at 11:16 Comment(1)
Thanks a lot. I was going in circles on this. He uses asdf. When using rbenv I had to add quotes to the install line like so RUBY_CONFIGURE_OPTS="--with-openssl-dir=$HOME/.openssl/openssl-1.1.1g" rbenv install 3.0.3Whittington
E
1

I have found a solution to this problem. To fix it you need to install libssl1.0-dev and remove the current version of libssl-dev. So if you need to install ruby 2.7.1 for example, you will have to execute these two commands

 sudo apt purge libssl-dev && sudo apt install libssl1.0-dev
 rvm install 2.7.1
Eutectoid answered 19/12, 2022 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.