How can I install the ruby gem openssl version 2.2.1

I was just forced to install the openssl gem because I needed a newer version than ships with ruby. Locally, for our docker environment, it works like a charm. However, on CircleCI it fails with the below message. Any help greatly appreciated.

Installing openssl 2.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/2.3.0 -r
./siteconf20220531-177-15ajnpq.rb extconf.rb
checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for openssl/ssl.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
extconf.rb:98:in `<main>': OpenSSL library could not be found. You might want to
use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is
installed. (RuntimeError)

To see why this extension failed to compile, please check the mkmf.log which can
be found here:


extconf failed, exit code 1

Gem files will remain installed in
/home/circleci/repo/vendor/bundle/ruby/2.3.0/gems/openssl-2.2.1 for inspection.
Results logged to

An error occurred while installing openssl (2.2.1), and Bundler cannot
Make sure that `gem install openssl -v '2.2.1' --source ''`
succeeds before bundling.

In Gemfile:

Exited with code exit status 5
CircleCI received exit code 5


This issue can be caused by openSSL not being installed on the based image that you are using as the gem attaches to the installed version of openSSL so if it is missing it will fail.

If it is installed it can still fail due to not finding the correct location but this can be defined as explained within the error.

I also found a linked stackoverflow which I believe will help linked here.

Kind Regards
Owen Oliver