Installing Net::SSLeay on OS X El Capitan

On Mac OS, I leave the system Perl alone and use Perlbrew to manage my custom Perl installations. I also install cpanm using perlbrew:

$ perlbrew install-cpanm

and then use cpanm to install packages from CPAN.

If you use LWP::UserAgent or HTTP::Tiny to talk to an https:// endpoint, you will need to install IO::Socket::SSL, which in turn depends on Net::SSLeay.

On OS X El Capitan (10.11.1), building Net::SSLeay fails with the following error:

SSLeay.xs:163:10: fatal error: ‘openssl/err.h’ file not found
#include <openssl/err.h>

The problem is that Apple no longer ships openssl headers:
http://lists.apple.com/archives/macnetworkprog/2015/Jun/msg00025.html

Thankfully, the fix is simple. Download the OpenSSL source from https://www.openssl.org (version 0.9.8zg).

If you use Safari, the file will be automatically gunzipped to openssl-0.9.8zg.tar in your ~/Downloads folder. Untar it:

$ tar -xvf openssl-0.9.8zg.tar

Enter the openssl-0.9.8zg folder and run make.

$ cd openssl-0.9.8zg
$ make

This will fail, but you will now have an include folder under your current folder. Inside this folder, will be a single folder called openssl that has a bunch of .h files symlinked to a ../../crytpo and ../../ssl. i.e.

openssl-0.9.8zg > include > opensssl > [bunch of .h symlinks]

Now all we have to do is symlink the openssl folder to /usr/local/include

$ cd /usr/local/include
$ sudo ln -s /Users/<your_user_name>/Downloads/openssl-0.9.8zg/include/openssl/

Be sure to change <your_user_name> to, well, your user name :)

That’s it. Try reinstalling IO::Socket:SSL with cpam and things should work this time.

p.s. I tried this with OpenSSL 1.0 as well, but Net::SSLeay (v.1.72 — the latest as of 18 Nov 2015). It compiled but all the tests failed with the following error:

Can’t load ‘/Users/dgulati/.cpanm/work/1447863075.28765/Net-SSLeay-1.72/blib/arch/auto/Net/SSLeay/SSLeay.bundle’ for module Net::SSLeay: dlopen(/Users/dgulati/.cpanm/work/1447863075.28765/Net-SSLeay-1.72/blib/arch/auto/Net/SSLeay/SSLeay.bundle, 2): Symbol not found: _EVP_MD_do_all_sorted

So looks like Net::SSLeay hasn’t been updated yet to work with OpenSSL 1.x releases.