アルパカログ

Webエンジニア兼マネージャーがプログラミングやマネジメント、読んだ本のまとめを中心に書いてます。

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

f:id:otoyo0122:20200822224847p:plain:w300

Macに入れたrbenvでRubyをインストールしようとして、OpenSSLライブラリのLoadErrorになってしまう場合がある。

/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をインストールすると良い。

$ brew update
$ brew install openssl