アルパカログ

カスタマーサポート (CS) とエンジニアリングを掛け算したい CRE (Customer Reliability Engineer) が気になる技術や思ったことなど。

【macOS/rbenv】OpenSSLのエラーでRubyのインストールが失敗する場合の解決方法

macOS にて rbenv で Ruby 2.4.4 や 2.5.1 をインストールしようとして次のような OpenSSL 関連のエラーが出る場合の解決方法。

/private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require': dlopen(/private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/.ext/x86_64-darwin17/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
  Referenced from: /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/.ext/x86_64-darwin17/openssl.bundle
  Reason: image not found - /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/.ext/x86_64-darwin17/openssl.bundle
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/.ext/common/openssl.rb:13:in `<top (required)>'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/security.rb:12:in `<top (required)>'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/package.rb:44:in `<top (required)>'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/installer.rb:10:in `<top (required)>'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /private/var/folders/c8/kt3b8mz57nn7f3l9jh0ps_2r0000gn/T/ruby-build.20180924132328.72126/ruby-2.4.4/lib/rubygems/core_ext/kernel_require.rb:55:in `require'
    from ./tool/rbinstall.rb:653:in `<module:RbInstall>'
    from ./tool/rbinstall.rb:596:in `<main>'
make: *** [do-install-all] Error 1

Homebrew で OpenSSL を更新してあげればOK。

$ brew update
$ brew install openssl