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?

【Ruby 3.3.5 インストール失敗時の解決法】BUILD FAILEDエラーと xcode-select --install での修正

Posted at

はじめに

Ruby環境の構築中に rbenv install 3.3.5 を実行したとき、以下のようなエラーが表示されることがあります。

(base) -zsh ~ % rbenv install 3.3.5
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.5.tar.gz...
-> curl -q -fL -o ruby-3.3.5.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.1M  100 21.1M    0     0  10.4M      0  0:00:02  0:00:02 --:--:-- 10.4M
==> Installing ruby-3.3.5...
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.5" --with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-gmp-dir=/opt/homebrew/opt/gmp --with-ext=openssl,psych,+

BUILD FAILED (macOS 15.1.1 on arm64 using ruby-build 20241225.2-3-g068c4047)

You can inspect the build directory at /var/folders/t_/1z86vw2d6dn88v7lrc76_7pc0000gn/T/ruby-build.20250112232158.7164.VkLYpv
See the full build log at /var/folders/t_/1z86vw2d6dn88v7lrc76_7pc0000gn/T/ruby-build.20250112232158.7164.log

このエラーの原因として頻繁に挙げられるのが、Command Line Tools (CLT) for Xcodeの未インストール または 設定の破損です。このツールが不足していると、ruby-build に必要なCコンパイラが使用できなくなり、Rubyのインストールに失敗します。本記事では、「このエラーが出たときになぜ xcode-select --install が必要なのか」 を詳しく説明します。

1. エラーの原因

ruby-build は、Rubyのインストール時にCコンパイラや関連するビルドツールを利用します。これらのツールは Command Line Tools (CLT) に含まれており、特に以下のような状況で問題が発生します。

よくあるエラーの例

checking whether the C compiler works... no
configure: error: C compiler cannot create executables

このエラーの原因は、clang や xcrun などのコンパイラツールのパスが無効か、ツールそのものが不足しているためです。

2. なぜ xcode-select --install が必要か

xcode-select --install は、Command Line Tools をインストールし、以下の重要なコンパイラツールを提供します。

ツール 説明
clang C言語コンパイラ。Rubyや他のライブラリをビルドする際に必要
make ビルドのプロセス管理ツール
xcrun macOSの開発者ツールを管理

xcode-select --install を実行しないと、Rubyをビルドするために必要なこれらのツールが使えないため、インストールが失敗します。

3. 解決手順

以下の手順で問題を解決できます。

1. Command Line Tools のインストール

xcode-select --install

インストールが始まり、完了するまで待ちます。

2. Rubyの再インストール

rbenv install 3.3.5

3. インストールが成功することを確認

ruby -v

4. 追加のトラブルシューティング

エラーが続く場合は、パスのリセットを行います。

sudo xcode-select --reset

まとめ

このエラーは コンパイラツール不足 に起因するものであり、xcode-select --install で解決できます。エラーメッセージが直接 xcrun と言及していなくても、内部でこのツールが使用されている点に注意してください。これでRuby 3.3.5のインストールがスムーズに進むはずです!

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