Could not find directory of OpenSSL installation

Ran into this error when compiling some software from source:

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
compilation process.

The fix is, luckily, rather easy.

Mac OSX / Homebrew#

If you have Homebrew installed:

$ brew install openssl@3

(This used to be [email protected], but Homebrew disabled that formula in late 2024 now that OpenSSL 1.1 is end-of-life. The openssl-sys crate builds fine against OpenSSL 3.)

Debian / Ubuntu#

Using the apt package manager:

$ apt install pkg-config libssl-dev

Fedora / RHEL / CentOS#

And using yum:

$ yum install pkg-config openssl-devel

Or with the newer dnf package manager:

$ dnf install pkg-config openssl-devel