18
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenSSLが予期せず1.1にバージョンアップして、rails s が起動しなくなった場合の対処法

Last updated at Posted at 2020-04-23

発生した問題

brew update && brew upgrade node-build というコマンドを実行したところ、予期せずOpenSSLのバージョンが1.0から1.1に上がってしまった。
その結果、rails sしたときに以下のようなエラーが出てサーバーが起動しなくなった。

$ rails s
Traceback (most recent call last):
    46: from bin/rails:4:in `<main>'
    45: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `require'
    44: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:257:in `load_dependency'
(略)
     3: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
     2: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
     1: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': dlopen(/Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
  Referenced from: /usr/local/opt/postgresql@9.6/lib/libpq.5.dylib
  Reason: image not found - /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle

どうやらPostgreSQLがopenssl1.0のlibssl.1.0.0.dylibというライブラリを参照していて、それが見つからなくなったのがエラーの原因っぽい。

解決策

シンボリックリンクを使って、OpenSSL1.0時代のライブラリを(仮想的に)復活させる。

ln -s /usr/local/opt/openssl/lib/libssl.1.1.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

ただし、これだけでは以下のような別のエラーが出る。

$ rails s                                                                                        
Traceback (most recent call last):
    46: from bin/rails:4:in `<main>'
    45: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `require'
    44: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:257:in `load_dependency'
(略)
     3: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
     2: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
     1: from /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': dlopen(/Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (LoadError)
  Referenced from: /usr/local/opt/postgresql@9.6/lib/libpq.5.dylib
  Reason: image not found - /Users/jnito/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pg-1.2.3/lib/pg_ext.bundle

というわけで、libcrypto.1.0.0.dylibも同様に復活させる。

ln -s /usr/local/opt/openssl/lib/libcrypto.1.1.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib

これでrails sでサーバーが起動するようになった。

(ほかに何かもっと適切な解決策があれば教えてください!)

追記

Rubyをビルドし直す、という方法もあるようです。(同僚の@pi_chanからの情報)

18
8
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?