Diary

[Mac] rbenv openssl [BUILD FAILED] [make: *** [all] Error 2]

1 Mins read

Needed an old environment so hit this issue setting up Xcode and Ruby on a legacy Mac. Leaving a note.

20220315

■Environment
macOS High Sierra 10.13.6
Homebrew 3.4.1-67-gb31d8e9
rbenv 1.2.0

Got this error:

Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...

BUILD FAILED (Mac Os X 10.13.6 using ruby-build 20220218)

Inspect or clean up the working tree at /var/folders/rc/9hwgt2nd0rxgjzvt9kc0zgph0000gn/T/ruby-build.20220315231102.889.ggie1q
Results logged to /var/folders/rc/9hwgt2nd0rxgjzvt9kc0zgph0000gn/T/ruby-build.20220315231102.889.log

Last 10 log lines:
/usr/include/CommonCrypto/CommonRandom.h:35:9: error: unknown type name 'CCCryptorStatus'
typedef CCCryptorStatus CCRNGStatus;
        ^
crypto/rand/rand_unix.c:385:47: error: use of undeclared identifier 'kCCSuccess'
    if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess)
                                              ^
2 errors generated.
make[1]: *** [crypto/rand/rand_unix.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

So you need OpenSSL 1.0. This command installs “rbenv/tap/openssl@1.0 1.0.2t”:

#Install OpenSSL1.0
brew install rbenv/tap/openssl@1.0

#Set environment variable [hoge is your username]
echo 'export PATH="/usr/local/opt/openssl@1.0/bin:$PATH"' >> /Users/hoge/.bash_profile
#Reflect environment variable
source .bash_profile

#If needed, reflect environment variable
export LDFLAGS="-L/usr/local/opt/openssl@1.0/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.0/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.0/lib/pkgconfig"

#This is needed for subsequent commands!
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl@1.0`"

#Install whatever Ruby version you want
rbenv install 2.6.9

On macOS, OpenSSL affects other things too.

OpenSSL also impacts the mysql2 library used by Rails and others. Watch out if you’re using MySQL 5.6 or 5.7!

Before running bundle install, you need to set this in your .bundle/config file:

BUNDLE_BUILD__MYSQL2: "--with-ldflags=-L/usr/local/opt/openssl@1.0/lib --with-cppflags=-I/usr/local/opt/openssl@1.0/include"