Ubuntu にインストールされている openssl が見つからないため、openssl Ruby gem のインストールが失敗する
概要
私はこれをやっています:
$ apt-get install -y openssl
$ gem install openssl -- --with-openssl-include=/usr/include/openssl
失敗します:
...
checking for openssl/ssl.h... yes
checking for CRYPTO_malloc() in -lcrypto... yes
checking for SSL_new() in -lssl... yes
checking for LIBRESSL_VERSION_NUMBER in openssl/opensslv.h... no
checking for OpenSSL version >= 1.0.2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-3.0.1/bin/$(RUBY_BASE_NAME)
--with-openssl-dir
--with-openssl-include=${openssl-dir}/include
--with-openssl-lib=${openssl-dir}/lib
--with-kerberos-dir
--without-kerberos-dir
--with-kerberos-include
--without-kerberos-include=${kerberos-dir}/include
--with-kerberos-lib
--without-kerberos-lib=${kerberos-dir}/lib
--with-nsl-dir
--without-nsl-dir
--with-nsl-include
--without-nsl-include=${nsl-dir}/include
--with-nsl-lib
--without-nsl-lib=${nsl-dir}/lib
--with-nsllib
--without-nsllib
--with-socket-dir
--without-socket-dir
--with-socket-include
--without-socket-include=${socket-dir}/include
--with-socket-lib
--without-socket-lib=${socket-dir}/lib
--with-socketlib
--without-socketlib
--with-crypto-dir
--without-crypto-dir
--with-crypto-include
--without-crypto-include=${crypto-dir}/include
--with-crypto-lib
--without-crypto-lib=${crypto-dir}/lib
--with-cryptolib
--without-cryptolib
--with-ssl-dir
--without-ssl-dir
--with-ssl-include
--without-ssl-include=${ssl-dir}/include
--with-ssl-lib
--without-ssl-lib=${ssl-dir}/lib
--with-ssllib
--without-ssllib
extconf.rb:136:in `<main>': OpenSSL >= 1.0.2 or LibreSSL >= 3.1.0 is required (RuntimeError)
gem install を機能させるために渡す適切な引数は何ですか?ちなみに、これは機能します:
$ which openssl
/usr/bin/openssl
$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
解決策
行から:
--ruby=/usr/local/rvm/rubies/ruby-3.0.1/bin/$(RUBY_BASE_NAME)
Ruby 3.0.1 を使用していて、openssl 3 をインストールしようとしているようです。3.1 より前の Ruby バージョンは openssl3 に対応していません。新しい 3.1 をインストールしてみるか、3.0.1 が必須の場合は openssl を 1.0 にダウングレードしてください。
RVM を使用しているので、次のことを試してください。
rvm install 3.1.4 --with-openssl-dir=<the directory you have>
次に、openssl gem のインストールを試みることができます。