LoginSignup
2
1

More than 1 year has passed since last update.

【Mac】Ruby3.1.1がインストールできなくて辛かった

Last updated at Posted at 2022-03-22

なんとなく「Rails7を使ってみよう!せっかくだからRubyも新しいの入れとくか!」と思い立ったものの、全然全くインストールできずハマったのでのでその時の対処法をメモ。

実行環境:macOS Monterey(12.2.1)

エラー

ruby3.1.1をインストールしようとするもエラーを吐かれてしまう。

$ rbenv install 3.1.1

Last 10 log lines:
checking for llvm-strip... no
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/var/folders/r1/x9mwdc5s12z1fj1361bzv8z00000gn/T/ruby-build.20220322144842.18804.Za253O/ruby-3.1.0':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

やってみた1: Xcode再インストール

ググると「Xcodeを入れ直す直すべし」との声が多数あったので、XcodeとCommandLineToolsを再インストール。
[参考] https://blog.nocorica.jp/2017/01/rbenv-failed/

→同じエラーが出た。

ログを読む

See 'config.log' for more detailsと言っているのでとりあえず見てよう(先に見ればいいのに)。

$ cd /var/folders/r1/x9mwdc5s12z1fj1361bzv8z00000gn/T/ruby-build.20220322140955.1606.YESPtG/ruby-3.1.1
$ cat config.log

~~略~~
clang: error: argument to '-V' is missing (expected 1 value)
clang: error: no input files
configure:5773: $? = 1
configure:5762: clang -qversion >&5
clang: error: unknown argument '-qversion'; did you mean '--version'?
clang: error: no input files
~~

clangが何か失敗してるっぽい。

$ clang -v

Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

ちゃんと入ってるのにね!なんだよ!!!!

やってみた2(解決): clangのバージョンを下げる

憤りながらも残念ながら「clangのバージョンを下げてみる」くらいしかやることが思いつかなかったので実行。
[参考] https://soluna-eureka.hatenablog.com/entry/2021/01/10/201341

llvmをインストール。

$ brew install llvm

パスを通す。

$ vi ~/.zshrc

# 下記を追加
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
# 追加ここまで

$ source .zshrc

clangはどうなったのか?

$ clang -v

Homebrew clang version 13.0.1
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

# 元の状態
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

ちょっと変わった。うーん意味があるか怪しいが、リベンジ。

$ rbenv install 3.1.1

~~略~~
Installed ruby-3.1.1 to /Users/hoge/.rbenv/versions/3.1.1

インストールできました!!やったね!!!!

2
1
1

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