macOS Bundle Install and OpenSSL Gem

Categories:

From time to time you run into an issue that requires no end of Googling to sort through. That was my case with using bundler and the OpenSSL gem on macOS Big Sur. Your Gemfile has the following contents:

[code lang=text]
gem "openssl"
[/code]

and when running bundle install you’re greeted with this nonsense:

[code lang=text]
extconf.rb:99: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)

An error occurred while installing openssl (2.2.0), and Bundler cannot continue.
[/code]

Using gem install “only” required the following incantation:

[code lang=text]
gem install openssl –install-dir vendor/bundle — –with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1h
[/code]

For the life of me, though, I couldn’t figure out how to apply the --with-openssl-dir to bundle!

Well, dear reader, here is how:

[code lang=text]
bundle config path vendor/bundle
bundle config build.openssl –with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1h
[/code]

The first line is obligatory and is the “modern” way of setting bundle‘s install path to vendor/bundle (which odds are you want anyway). The build.openssl setting will use the remaining information to pass to gem when installing openssl.

It goes without saying that the exact path used is dependent on your environment; for my Mac the OpenSSL headers and libraries were hanging out in the brew cellar.

Hopefully this post saves someone an hour or so!

Leave a Reply

Your email address will not be published. Required fields are marked *