Install Ruby 2.7.5 using RVM on Ubuntu 22.04

RVM is a great tool to manage multiple versions of Ruby when working on projects.

I was working on a Rails project which was using Ruby 2.7.5, so tried to install it using RVM’s standard installation process: rvm install 2.7.5. It fails, and in the log file you can see this:

+ command gem install /home/nilesh/.rvm/gem-cache/gem-wrappers-1.4.0.gem --local --no-document
ERROR:  Loading command: install (LoadError)
        cannot load such file -- openssl
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

After a bit of digging around in the issues mentioned on Github of RVM and rbenv, I found that Ruby 2.7.5 needs OpenSSL 1.1, but Ubuntu 22.04 comes with OpenSSL 3.0. One reference: Failed to build ruby 2.7.5 on ubuntu 22.04.

And thus, the solution:

tar xf openssl-1.1.1t.tar.gz
cd openssl-1.1.1t
./config --prefix=/usr/local/openssl1.1.1t --openssldir=/usr/local/openssl1.1.1t/etc
make -j$(nproc)
make -j$(nproc) install

After installation, configure the custom OpenSSL installation to point to the system CA certificates to avoid downloading the CA certificates separately:

cd /usr/local/openssl1.1.1t/etc
rmdir certs
ln -s /etc/ssl/certs certs

Now, for Ruby 2.7.5 installation:

rvm install 2.7.5 --with-openssl-dir=/usr/local/openssl1.1.1t

This installs successfully. Enjoy working on your project 😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: