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?

【2025年版】macOS Sequoia 15.5でRuby 3.0.2をインストールする方法

Posted at

【2025年版】macOS Sequoia 15.5でRuby 3.0.2をインストールする方法

はじめに

macOS Sequoia 15.5 + Apple Silicon環境でRuby 3.0.2をインストールしようとしたところ、様々なエラーに遭遇しました。同じ問題で困っている方のために、解決方法をまとめます。

環境

  • macOS: 15.5 (Sequoia)
  • チップ: Apple Silicon (arm64)
  • Xcode: Command Line Tools最新版
  • Homebrew: 最新版
  • 目標: Ruby 3.0.2のインストール

発生した問題

1. 通常のrbenvインストールが失敗

rbenv install 3.0.2

以下のエラーが発生:

bigdecimal.c:249:5: error: 'maybe_unused' attribute cannot be applied to types
  249 |     ENTER(1);
      |     ^
bigdecimal.c:68:33: note: expanded from macro 'ENTER'
   68 | #define ENTER(n) volatile VALUE RB_UNUSED_VAR(vStack[n]);int iStack=0
      |                                 ^

2. 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.

解決方法

Step 1: OpenSSL@1.1の手動インストール

EOL前のOpenSSL@1.1を手動でインストールします。

# ローカルにtapを作成
brew tap-new akaishi/openssl@1.1

# EOL前の最後のコミットからFormulaをダウンロード
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/df0c4994aa4b2d61a86d38f4b954e8315dc4678c/Formula/o/openssl@1.1.rb -o /opt/homebrew/Library/Taps/akaishi/homebrew-openssl@1.1/Formula/openssl@1.1.rb

# OpenSSL@1.1をインストール
brew install akaishi/openssl@1.1/openssl@1.1

Step 2: 環境変数の設定

OpenSSL@1.1を使用するように環境変数を設定します。

export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.1 --disable-install-doc"

Step 3: bigdecimal.cのパッチ適用

macOS Sequoiaの新しいClangコンパイラとRuby 3.0.2の非互換性を解決するパッチを作成します。

# パッチファイルを作成
cat > ruby-3.0.2-exact-fix.patch << 'EOF'
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -68 +68 @@
-#define ENTER(n) volatile VALUE RB_UNUSED_VAR(vStack[n]);int iStack=0
+#define ENTER(n) volatile VALUE vStack[n];int iStack=0
EOF

Step 4: パッチを適用してRubyをインストール

# パッチを適用してRuby 3.0.2をインストール
cat ruby-3.0.2-exact-fix.patch | rbenv install --patch 3.0.2

Step 5: インストール確認

# インストールされたバージョンを確認
rbenv versions

# Ruby 3.0.2を使用
rbenv local 3.0.2

# バージョン確認
ruby -v

成功時の出力例

==> Downloading ruby-3.0.2.tar.gz...
==> Installing ruby-3.0.2...
-> patch -p1 --force -i "$TMPDIR/ruby-patch.xxxxx"
patching file 'ext/bigdecimal/bigdecimal.c'
-> ./configure "--prefix=$HOME/.rbenv/versions/3.0.2" --enable-shared ...
-> make -j 10
Installed ruby-3.0.2 to /Users/username/.rbenv/versions/3.0.2

代替案

1. より新しいRubyバージョンを使用

Ruby 3.0.2の代わりに、より新しいバージョンを使用することを検討してください:

# Ruby 3.1系や3.2系の方が現代的な環境での互換性が良い
rbenv install 3.1.6
rbenv install 3.2.5

2. .ruby-versionをgitignoreに追加

ローカル環境とプロダクション環境で異なるRubyバージョンを使用する場合:

# .ruby-versionをgit管理から除外
echo ".ruby-version" >> .gitignore

# Gemfileで柔軟にバージョン指定
# ruby "~> 3.0.0"

3. Dockerを使用

環境の問題を完全に回避する方法:

FROM ruby:3.0.2-alpine
WORKDIR /app
RUN apk add --no-cache build-base git postgresql-dev
COPY Gemfile* ./
RUN bundle install

注意事項

  • Ruby 3.0.2はEOL(End of Life)済みのため、セキュリティアップデートが提供されません
  • 本番環境では使用を避けることを強く推奨します
  • 開発環境のみでの使用に留めることをお勧めします
  • 可能な限り新しいバージョンへの移行を検討してください

トラブルシューティング

パッチ適用が失敗する場合

# より強力なコンパイラエラー無視フラグを試す
export CFLAGS="-w"
export CPPFLAGS="-w"
rbenv install 3.0.2

Rosettaを使用する場合

# x86_64アーキテクチャでビルド
arch -x86_64 rbenv install 3.0.2

まとめ

macOS Sequoia 15.5でRuby 3.0.2をインストールするには:

  1. OpenSSL@1.1を手動でインストール
  2. bigdecimal.cのコンパイラエラーをパッチで修正
  3. 適切な環境変数を設定

これらの手順により、レガシーなRuby環境でも現代的なmacOS環境で動作させることができます。

ただし、セキュリティの観点から、可能な限り新しいRubyバージョンへの移行を検討することをお勧めします。

参考情報

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?