puma gem - Failed to build gem native extension

I was getting the following error while installing puma gem

    $ gem install puma
    Fetching: puma-2.11.2.gem (100%)
    Building native extensions.  This could take a while...
    ERROR:  Error installing puma:
    ERROR: Failed to build gem native extension.

    ruby extconf.rb
    checking for BIO_read() in -lcrypto... no
    checking for BIO_read() in -llibeay32... no
    *** extconf.rb failed ***

Try the following

gem install puma -- --with-cppflags=-I/usr/local/opt/openssl/include
bundle install

You can also specify the gem version, like the following:

gem install puma -v '2.11.3' -- --with-cppflags=-I/usr/local/opt/openssl/include

I'm on OS X 10.12.4 and the comment @mahi added worked for me:

gem install puma -v '3.6.0' -- --with-opt-dir=/usr/local/opt/openssl

libssl1.0-dev installing helped to me. Try

apt-get install libssl1.0-dev

and then

gem install puma

Not my answer but this helped me install puma on macos (big sur) since there were warnings when building puma.

The command that I used is this:

gem install puma -- --with-cflags="-Wno-error=implicit-function-declaration"