1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gem コマンドが使えない(OpenSSL is not available.)

Last updated at Posted at 2025-02-11

今朝,

gem outdated

とやったら

ERROR:  While executing gem ... (Gem::Exception)
    OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)

が出た。はあ?

エラーの全文
ERROR:  While executing gem ... (Gem::Exception)
    OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request.rb:53:in 'Gem::Request.configure_connection_for_https'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request/https_pool.rb:7:in 'Gem::Request::HTTPSPool#setup_connection'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request/http_pool.rb:40:in 'Gem::Request::HTTPPool#make_connection'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request/http_pool.rb:21:in 'Gem::Request::HTTPPool#checkout'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request.rb:135:in 'Gem::Request#connection_for'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request.rb:193:in 'Gem::Request#perform_request'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/request.rb:160:in 'Gem::Request#fetch'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/remote_fetcher.rb:317:in 'Gem::RemoteFetcher#request'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/remote_fetcher.rb:213:in 'Gem::RemoteFetcher#fetch_http'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/remote_fetcher.rb:252:in 'Gem::RemoteFetcher#fetch_path'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/remote_fetcher.rb:293:in 'Gem::RemoteFetcher#cache_update_path'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/source.rb:190:in 'Gem::Source#load_specs'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/spec_fetcher.rb:285:in 'Gem::SpecFetcher#tuples_for'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/spec_fetcher.rb:252:in 'block in Gem::SpecFetcher#available_specs'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/source_list.rb:94:in 'Array#each'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/source_list.rb:94:in 'Gem::SourceList#each_source'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/spec_fetcher.rb:247:in 'Gem::SpecFetcher#available_specs'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/spec_fetcher.rb:91:in 'Gem::SpecFetcher#search_for_dependency'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1167:in 'block in Gem::Specification.outdated_and_latest_version'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1163:in 'Array#each'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1163:in 'Gem::Specification.outdated_and_latest_version'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/commands/outdated_command.rb:29:in 'Enumerator#each'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/commands/outdated_command.rb:29:in 'Gem::Commands::OutdatedCommand#execute'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/command.rb:326:in 'Gem::Command#invoke_with_build_args'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:253:in 'Gem::CommandManager#invoke_command'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:194:in 'Gem::CommandManager#process_args'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:152:in 'Gem::CommandManager#run'
	/Users/XXXX/.rbenv/versions/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/gem_runner.rb:57:in 'Gem::GemRunner#run'
	/Users/XXXX/.rbenv/versions/3.4.1/bin/gem:12:in '<main>'

昨夜までなんともなかったぞ。そのあと何かをインストールしたりアップデートしたりした覚えはない。

環境

  • macOS Sequoia 15.3(24D60)
  • ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24]
  • RubyGems 3.6.3
  • Ruby は rbenv でインストールしている

brew info openssl やると「Installed」が出てくるので,openssl パッケージが何らかの原因で消えた,というわけでもないようだ。

gem コマンド自体は動作して,gem -v とか gem list, gem help とかは正常。
おそらくは,要するに gem outdatedgem install, gem upddate などネット接続する系のサブコマンドで上記エラーが出るぽい。

bundle update のたぐいも当然ダメ。

OS の再起動などもやってみるが,とくに変わりなし。

同じターミナル上で curl コマンドでネットからファイルを落としたりはできる。

進展があったら追記します。

追記 1

その後,@ki073 さんの非常に有益なコメントを頼りにいろいろ実験してみて,おおむね何がどうなってたのか判った気がする。

まず予備知識として,

  • Ruby のインストール(ビルド)には openssl が必要
  • Ruby をインストールするとき,RUBY_CONFIGURE_OPTS という環境変数があればそれが参照される
  • この環境変数で,--with-openssl-dir=/opt/homebrew/opt/openssl@3 のようにして openssl のディレクトリーパスを指定することができる
  • gem outdatedgem install など,ネットワークアクセスをする gem のサブコマンドは,実行時に openssl が必要

ということがある(たぶん)。

私の環境では,Homebrew で openssl パッケージがインストールしてあった。
これによる openssl コマンドは下記のパスにあった。
/opt/homebrew/bin/openssl

それとは別に /usr/bin/openssl コマンドも存在していたが,おそらくそれは今回の不具合には関係していない(有っても無くても変わらなかったと思う)。

ビルド時に指定される openssl のディレクトリーが不具合に関わっていることは間違いない。

RUBY_CONFIGURE_OPTS を指定して

RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/Cellar/openssl@3/3.4.0" rbenv install 3.3.7

としてインストールした Ruby では問題は起きなかったので。

しかし過去にインストールしていた Ruby で,なぜ突然問題が起きるようになったのか。

これを調べていて,あることに気づいた。
なにげに

echo $RUBY_CONFIGURE_OPTS

とやったら

--with-openssl-dir=/opt/homebrew/opt/openssl@1.1

と表示されたのだ。
えっ,RUBY_CONFIGURE_OPTS の値って定義されてたんだ?

しかし openssl 1.1 系はインストールされてないぞ?

とりあえず RUBY_CONFIGURE_OPTS がどこで定義されているか調べると,

.zprofile

export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"

という行があった。これか。
brew --prefix openssl@1.1 を実行すると

/opt/homebrew/opt/openssl@1.1

が返る。これが openssl のディレクトリーとして指定されていたわけだ。

ここからは推測になる。

おそらく,不具合が起こる前,openssl は Homebrew によって 1.1 系と 3 系の両方のバージョンがインストールされていた。

そして,環境変数 RUBY_CONFIGURE_OPTS の値は,1.1 系のほうを使うように設定されていた(これは推測でなく事実)。

だから,過去に rbenv でインストールした Ruby の全バージョンは openssl 1.1 系を使うようにビルドされていた。

それが,つい最近(昨日? 一昨日? もう少し前?),何らかの原因で openssl 1.1 系が消えた(そんなことある?)
よく分からないが,改めて

brew install openssl@1.1

しようとしても,

Error: openssl@1.1 has been disabled because it is not supported upstream! It was disabled on 2024-10-24.

とエラーが出てインストールできない。

openssl 1.1 系を使う前提でビルドされた Ruby で gem install などしようとしても 1.1 系が既に無いので

OpenSSL is not available.

とエラーが出て動かなかったのだ。

ここまでの理解が正しければ,過去にインストールした Ruby の全バージョンは,openssl 3 系を使うようにビルドしなおす必要がある。

ということで,.zprofile を以下のように書き換えることにした。

-export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
+export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)"

書き換えて,念のため新しいシェルで環境変数の値を確認:

$ echo $RUBY_CONFIGURE_OPTS
--with-openssl-dir=/opt/homebrew/opt/openssl@3

おーけー。

この状態で,Ruby 3.4.1 を

rbenv install 3.4.1

で再インストールしたら,万事解決した。
ちなみに Ruby 3.4.1 をアンインストールしないで再インストールした場合,インストールしてあった gem たちは温存されるようだ。gem の再インストールはしなくて済んだ。
めでたしめでたし。

追記 2

めでたしめでたし,でもなかった。

Gemfile のあるディレクトリーで

bundle check

とやったら

Source locally installed gems is ignoring #<Bundler::StubSpecification name=strscan version=3.1.2 platform=ruby> because it is missing extensions

みたいなエラー(警告?)がどばーっと出た。

エラー全文
Source locally installed gems is ignoring #<Bundler::StubSpecification name=strscan version=3.1.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=pathname version=0.4.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.9.1 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=fiddle version=1.1.6 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=etc version=1.4.5 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=strscan version=3.1.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=pathname version=0.4.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.9.1 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=fiddle version=1.1.6 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=etc version=1.4.5 platform=ruby> because it is missing extensions
The Gemfile's dependencies are satisfied

どうやら「gem の再インストールをせずに済んだ」は幻想だったようだ。

言われた gem を全部再インストールしたら正常になった。
まあ,全 gem をインストールし直すよりは楽だった。

1
0
4

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?