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

Homebrew で旧バージョンの OpenSSL をインストールする (3.6.0 → 3.5.4)

Last updated at Posted at 2025-10-06

背景

現在 (2025/10/06 (月) 時点) 、Homebrew で配布されている OpenSSL (openssl@3) のバージョンは 3.6.0。

openssl@3 のバージョン

しかし、このバージョンでは Ruby の OpenSSL ライブラリが正常に動作しない 😢

例えば、以下の検証用コードを実行すると、Net::HTTP.start 実行時に OpenSSL::SSL::SSLError エラーが発生する。

$ openssl --version
OpenSSL 3.6.0 1 Oct 2025 (Library: OpenSSL 3.6.0 1 Oct 2025)
require 'net/http'
require 'uri'

RUBY_VERSION
#=> "3.4.6"

# Ruby の OpenSSL ライブラリのバージョン。
OpenSSL::VERSION
#=> "3.3.0"

uri = URI('https://example.com')
request = Net::HTTP::Post.new(uri)

# certificate verify failed (unable to get certificate CRL) (OpenSSL::SSL::SSLError)
# というエラーが発生してしまい、HTTP 通信が失敗する 🆖
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end
# /Users/quanon/.rbenv/versions/3.4.6/lib/ruby/3.4.0/net/protocol.rb:46:in 'OpenSSL::SSL::SSLSocket#connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=23.215.0.136:443 state=error: certificate verify failed (unable to get certificate CRL) (OpenSSL::SSL::SSLError)

この問題を一時的に回避するために、Homebrew で 3.6.0 より前のバージョンの OpenSSL をインストールする。

今後も旧バージョンのライブラリをインストールしたくなる場合があるかもしれないので、そのためにも手順を残しておく。

追記 (2025/10/06 (月) 18:20)

Ruby の OpenSSL ライブラリの 3.3.1 がリリースされた。以下の修正 PR が含まれており、これをインストールすると解決する。

require 'net/http'
require 'uri'

RUBY_VERSION
#=> "3.4.6"

OpenSSL::VERSION
#=> "3.3.1"

uri = URI('https://example.com')
request = Net::HTTP::Post.new(uri)

# `OpenSSL::SSL::SSLError` エラーは発生せず、HTTP 通信が成功するようになった 🆗
# (ステータスコードが 4xx 系ではあるけど、単なる疎通確認なので 🆗)
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end
#=> #<Net::HTTPForbidden 403 Forbidden readbody=true>

旧バージョンの OpenSSL (3.5.4) をインストールする方法

# 現在利用している openssl@3 のバージョンは 3.6.0。
$ brew list --versions openssl@3
openssl@3 3.6.0
$ openssl --version
OpenSSL 3.6.0 1 Oct 2025 (Library: OpenSSL 3.6.0 1 Oct 2025)

# homebrew/core の履歴を使用できるように強制で tap する。
# 未実行だと時間が掛かる。
$ brew tap --force homebrew/core 

# 過去のバージョンを調べる。3.6.0 の 1 つ前のバージョンは 3.5.4 だと分かった。
$ git -C $(brew --repo homebrew/core) log -n 10 --follow -- $(brew formula openssl@3) | sed -nE 's/.*[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)[[:space:]]+.*/\1/p' | sort -u
3.5.2
3.5.3
3.5.4
3.6.0

# 自分専用の tap をローカルに新規作成する。
$ brew tap-new "$USER/old-openssl"

# homebrew/core の履歴からバージョンは 3.5.4 の formula を抽出する。
$ brew extract --version=3.5.4 openssl@3 "$USER/old-openssl"

# openssl@3 3.6.0 をアンインストールする。
brew uninstall --ignore-dependencies openssl@3

# openssl@3 3.5.4 をインストールする。
$ brew install "$USER/old-openssl/openssl@3.5.4"
==> Fetching downloads for: openssl@3.5.4
==> Fetching quanon/old-openssl/openssl@3.5.4
==> Downloading https://github.com/openssl/openssl/releases/download/openssl-3.5.4/openssl-3.5.4.tar.gz
Already downloaded: /Users/quanon/Library/Caches/Homebrew/downloads/9beae4c414a8d1538eb933c61d3f8e138a3238d184e1663cf2002c915c8ab422--openssl-3.5.4.tar.gz
==> Installing openssl@3.5.4 from quanon/old-openssl
==> perl ./Configure --prefix=/opt/homebrew/Cellar/openssl@3.5.4/3.5.4 --openssldir=/opt/homebrew/etc/openssl@3 --libdir=lib no-ssl3 no-ssl3-method no-zlib darwin64-arm64-cc enable-ec_nistp_64_gcc_128
==> make
==> make install MANDIR=/opt/homebrew/Cellar/openssl@3.5.4/3.5.4/share/man MANSUFFIX=ssl
==> make HARNESS_JOBS=8 test TESTS=-test_afalg
==> Caveats
To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@3/certs

and run
  /opt/homebrew/opt/openssl@3.5.4/bin/c_rehash
==> Summary
🍺  /opt/homebrew/Cellar/openssl@3.5.4/3.5.4: 7,556 files, 35.3MB, built in 4 minutes 10 seconds
==> Running `brew cleanup openssl@3.5.4`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).

# OpenSSL のバージョンが 3.5.4
$ brew list --versions openssl@3
(何も出力されない)
$ brew list --versions openssl@3.5.4
openssl@3.5.4 3.5.4
$ openssl version
OpenSSL 3.5.4 30 Sep 2025 (Library: OpenSSL 3.5.4 30 Sep 2025)

# バージョンが意図せず上がらないように固定する。
# 固定を解除する場合は pin を unpin に変えて実行する。
$ brew pin openssl@3.5.4

# 環境変数 LDFLAGS を設定する。
# LDFLAGS: 拡張ライブラリをリンクするときのリンカのオプション、ライブラリファイルのディレクトリを指定する。
$ export LDFLAGS="-L/opt/homebrew/opt/openssl@3.5.4/lib $LDFLAGS"

# Ruby をインストールし直す。
$ rbenv install 3.4.6
rbenv: /Users/quanon/.rbenv/versions/3.4.6 already exists
continue with installation? (y/N) y

この状態で先述の検証用コードを再び実行すると、Net::HTTP.start が成功する 🙆✨

require 'net/http'
require 'uri'

uri = URI('https://example.com')
request = Net::HTTP::Post.new(uri)

# `OpenSSL::SSL::SSLError` エラーは発生せず、HTTP 通信が成功するようになった 🆗
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end
#=> #<Net::HTTPForbidden 403 Forbidden readbody=true>

現バージョンの OpenSSL (3.6.0) に戻す方法

$ brew unpin openssl@3.5.4
$ brew uninstall openssl@3.5.4
$ brew untap "$USER/old-openssl"

$ brew install openssl@3
$ openssl version
OpenSSL 3.6.0 1 Oct 2025 (Library: OpenSSL 3.6.0 1 Oct 2025)

$ export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
$ rbenv install 3.4.6
rbenv: /Users/quanon/.rbenv/versions/3.4.6 already exists
continue with installation? (y/N) y
0
0
0

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