Ruby Build Failure with OpenSSL3

There may be no developer who has not encountered installation errors when using Ruby and rbenv. As a piece of evidence that Ruby and OpenSSL have bad chemistry with each other, you may be able to find a lot of questions line about the error like this.

This time, I tried to upgrade my Ruby environment to Ruby3 and encountered the following issue.

OpenSSL 3 - symbol not found in flat namespace '_SSL_get1_peer_certificate'

This is because OpenSSL 3 has SSL_get1_peer_certificate but Open SSL 1.1 does not, which has SSL_get_peer_certificate instead. When you build Ruby with OpenSSL 1.1 but puma running for Rails using Open SSL 3, the problem shows up.

This solution targets the developer using macOS and Homebrew to manage their system packages.

Short Answer

The quick answer to this problem is deleting OpenSSL 3 from your environment. If you use macOS and Homebrew, you will find which version is installed.

$ brew --prefix openssl
/usr/local/opt/[email protected]

It indicates that the system, including puma, can refer to OpenSSL 3. It might be better to uninstall this version completely. You may imagine changing the build option to compile puma with OpenSSL 1 can work.

$ bundle config build.puma \
    --with-opt-include=/usr/local/opt/[email protected]/include

But it did not work in my case. Eradicating the package from the system was the sole solution.