upinetree's memo

Web系技術の話題や日常について。

native extension に openssl を使う gem のビルドに失敗するときの対処法

homebrew で openssl をインストールした場合、今までだとbrew linkするだけで特に問題なく使えていたが、最近ではbrew linkができなくなった。

$ brew link openssl --force
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

その結果、 native extension のビルドに openssl を使う gem が正しく include できなくなった。 なので次のように設定した。 (参考: rbenv/ruby-build: Compile and install Ruby

$ cat ~/.zshrc
if [ $(uname) = "Darwin" ]; then
  export CONFIGURE_OPTS="--with-opt-dir=`brew --prefix openssl`"
  export RUBY_CONFIGURE_OPTS="--with-opt-dir=`brew --prefix openssl`"
fi

$ source ~/.zshrc

それでruby再ビルドしたらいけた。