AbstractBrain Answers About us

Error while installing openssl gem on MacOS with bundler

Question

An error occurred while installing openssl (2.2.2), and Bundler cannot continue.

How do I solve this error on MacOS?

I have upgraded MacOS, Xcode, Xcode command line tools, Homebrew and the Homebrew formula for openssl. Now when I run bundle install it doesn’t work and the installation of the openssl gem fails:

checking for OpenSSL version >= 1.0.1 and < 3.0.0... 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:
	--with-openssl-dir
	...

extconf.rb:113:in `<main>': OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is required (RuntimeError)

Answer

As you can see in the error above the --with-openssl-dir option is not explicitly set.

It may not find a directory for openssl or it may be using a different openssl version that is not compatible (e.g. you can also type openssl version to see the version number).

We can fix the error by passing the Homebrew directory where openssl is installed as an option:

bundle config build.openssl --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1s

Then run bundle install and it will successfully install the openssl gem.

If you prefer you can also pass the same option when you install the gem manually:

gem install openssl -- --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1s