Installing Ruby 2.3 or below on Ubuntu 17 and above

Updated . Posted . Visible to the public. Deprecated.

We now use a fork of ruby-build to work around this issue. See this card.

From Ubuntu 17, rbenv fails to install Ruby below 2.4 because of a mismatching OpenSSL dependency: it needs libssl1.0-dev for the installation process, but recent Ubuntus come with libssl-dev.

From the linked StackOverflow comment:

As far as I know (and tested), Ruby versions < 2.4 requires libssl1.0, while >2.4 libssl1.1+. The two libssl packages conflict with each other, so you can't have both of them, so I had to juggle the libs in order to install the required ruby version. To make things even funnier (or more complicated), Ruby <2.4 tends to require gcc-6 instead of the current upstream version (which is 7).

Install Ruby like this:

# Ruby 1.8.7
apt install libssl1.0-dev # This will remove libssl-dev
CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline --with-openssl-dir=/usr/include/openssl" rbenv install 1.8.7-p375
apt install libssl-dev # Restore libssl-dev

# Ruby 1.9 to 2.3
apt install libssl1.0-dev # This will remove libssl-dev
CC=$(which gcc-6) rbenv install $version
apt install libssl-dev # Restore libssl-dev

# Ruby 2.4+
rbenv install $version

Temporarily installing the libssl1.0-dev package might also be necessary if you want to install certain gems like puma for old Rubies.

Example error backtace

Checking out http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7...
Installing ruby-1.8.7-p375...

WARNING: ruby-1.8.7-p375 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.


BUILD FAILED (Ubuntu 18.04 using ruby-build 20180424)

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

Last 10 log lines:
             ^
ossl_ssl.c: In function ‘ossl_ssl_get_cipher’:
ossl_ssl.c:1230:12: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
     cipher = SSL_get_current_cipher(ssl);
            ^
Makefile:198: recipe for target 'ossl_ssl.o' failed
make[1]: *** [ossl_ssl.o] Error 1
make[1]: Leaving directory '/tmp/ruby-build.20180507142116.3799/ruby-1.8.7-p375/ext/openssl'
Makefile:293: recipe for target 'all' failed
make: *** [all] Error 1

You can check installed libssl packages using apt list:

$ apt list --installed | grep libssl
libssl-dev/bionic,now 1.1.0g-2ubuntu4 amd64 [installed]
libssl-doc/bionic,bionic,now 1.1.0g-2ubuntu4 all [installed,automatic]
libssl1.0.0/bionic,now 1.0.2n-1ubuntu5 amd64 [installed]
libssl1.1/bionic,now 1.1.0g-2ubuntu4 amd64 [installed]
Dominik Schöler
Last edit
Emanuel
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2019-07-05 08:05)