This post was originally written in 2022 for Ubuntu 22.04 but has been updated for 24.04 too
I’ve recently upgraded to Ubuntu 24.04 on my main machine and laptop. As I use a mixture of Rails versions for different apps I maintain, I needed to install Ruby 3.0, 2.7 & 2.6 alongside 3.1.
Because Ubuntu 24.04 & 22.04 come with OpenSSL 3.0, Ruby 3.0 and below don’t support this so an older version is required for these versions to be installed.
Compiling OpenSSL
This guide assumes you’ve already got build-essential
installed.
Firstly download OpenSSL 1.1.1w and extract it:
wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz
tar zxvf openssl-1.1.1w.tar.gz
Once extracted, we need to configure where this version will be installed. In my case,
I want it in a hidden folder in my home directory ~/.openssl/version
export OPENSSL=$HOME/.openssl/openssl-1.1.1w
cd openssl-1.1.1w
./config --prefix=$OPENSSL --openssldir=$OPENSSL
make
make test
make install
As this doesn’t include any certificates, I just symlink the main OpenSSL certs folder into this version like so:
rm -rf $OPENSSL/certs
ln -s /etc/ssl/certs $OPENSSL/certs
Install Ruby
Once OpenSSL 1.1.1g is installed, we can now install Ruby 3.0 and below but telling ruby-build
to use this version of OpenSSL. In this example, I’m using rbenv
but it should
work the same way with asdf
.
# Ruby 3.0
RUBY_CONFIGURE_OPTS=--with-openssl-dir=$OPENSSL rbenv install 3.0.7
# Ruby 2.7
RUBY_CONFIGURE_OPTS=--with-openssl-dir=$OPENSSL rbenv install 2.7.8
# Ruby 2.6
RUBY_CONFIGURE_OPTS=--with-openssl-dir=$OPENSSL rbenv install 2.6.10
# Ruby 2.5
RUBY_CONFIGURE_OPTS=--with-openssl-dir=$OPENSSL rbenv install 2.5.9
And that’s it! You should now have older Ruby versions installed on Ubuntu 24.04 & 22.04.