結論をお急ぎの方は末尾をご覧くださいませ。
背景
2019年の暮れ頃から、ruby-build (rbenv install) で Ruby をインストールする際、Homebrew でインストールしている OpenSSL が使用されず、ダウンロード&ビルドされるようになりました。
$ rbenv install 2.6.4
Downloading openssl-1.1.1d.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2
Installing openssl-1.1.1d...
Installed openssl-1.1.1d to /Users/foo/.rbenv/versions/2.6.4
Downloading ruby-2.6.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.4.tar.bz2
Installing ruby-2.6.4...
ruby-build: using readline from homebrew
Installed ruby-2.6.4 to /Users/foo/.rbenv/versions/2.6.4
詳細はこちらの PR にある通り:
Don’t look for Homebrew openssl by gfguthrie · Pull Request #1375 · rbenv/ruby-build
互換性のないバージョンがインストールされているかもしれないし、ユーザーがどのバージョンをインストールしているかわかっていないかもしれないし、それらをいちいちケアするのが大変だということでしょうか。
一方で、上級者は RUBY_CONFIGURE_OPTS="--with-openssl-dir=/my-openssl-directory"
オプションを指定することで ruby-build がインストールする OpenSSL を使わないようにすることもできる、と。
個別に OpenSSL がインストールされるのも別に悪くはないのですが、いちいちダウンロードしてビルドするのもなんだし、ストレージもあまり余裕がないので、どちらかというと Homebrew でインストールした OpenSSL を使いたい。
RUBY_CONFIGURE_OPTS 変数の設定
Homebrew で ruby-build をインストール/アップグレードした際にも、Homebrew の OpenSSL をリンクしたい場合は RUBY_CONFIGURE_OPTS
環境変数を設定せよという補足説明が表示されますが
==> Caveats
ruby-build installs a non-Homebrew OpenSSL for each Ruby version installed and these are never upgraded.
To link Rubies to Homebrew's OpenSSL 1.1 (which is upgraded) add the following
to your ~/.config/fish/config.fish:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
Note: this may interfere with building old versions of Ruby (e.g <2.4) that use
OpenSSL <1.1.
いかんせん、上記 export 〜
は fish shell ではエラーになりますので、
set -x RUBY_CONFIGURE_OPTS --with-openssl-dir=(brew --prefix openssl@1.1)
とすれば OK です。