M1MacでRubyのインストールに失敗する

エラー

Installing ruby-3.1.0...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 13.3.1 using ruby-build 20230512)

Inspect or clean up the working tree at /var/folders/nk/d88m3z390qjbgp5yjln8nnt80000gn/T/ruby-build.20230526145532.33223.Lm7fcQ
Results logged to /var/folders/nk/d88m3z390qjbgp5yjln8nnt80000gn/T/ruby-build.20230526145532.33223.log

Last 10 log lines:
linking shared-library libruby.3.1.dylib
transdb.h updated
ld: library not found for -lcapstone
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libruby.3.1.dylib] Error 1
make: *** Waiting for unfinished jobs....
transform_mjit_header: making external definition static inline: rb_vm_lvar_exposed, Init_vm_stack_canary, rb_vm_opt_cfunc_p, rb_vm_opt_mod, rb_vm_ic_hit_p, rb_vm_splat_array, rb_vm_defined, rb_vm_cc_general, rb_aliased_callable_method_entry, rb_find_defined_class_by_owner, rb_vm_call_ivar_attrset_p, rb_iseq_only_kwparam_p, rb_iseq_only_optparam_p, rb_vm_set_ivar_idx, rb_vm_setinstancevariable, rb_vm_setclassvariable, rb_vm_getclassvariable, rb_vm_rewrite_cref, rb_vm_get_cref, rb_vm_block_ep_update, rb_vm_cref_new_toplevel, rb_vm_cref_dup_without_refinements, rb_vm_frame_block_handler, rb_vm_cframe_keyword_p, rb_vm_ep_local_ep
transform_mjit_header: making declaration static inline: rb_vm_lvar_exposed, rb_vm_lvar_exposed, Init_vm_stack_canary, rb_vm_rewrite_cref, rb_vm_frame_block_handler, rb_vm_block_ep_update, rb_vm_ep_local_ep
transform_mjit_header: SKIPPED to transform: __sigbits, isspecial, isrune, isphonogram, isnumber, isideogram, ishexnumber, digittoint, toupper, tolower, toascii, isxdigit, isupper, isspace, ispunct, isprint, islower, isgraph, isdigit, iscntrl, isblank, isalpha, isalnum, __wcwidth, __isctype, __istype, isascii, __sincospi, __sincospif, __sincos, __sincosf, __inline_isnormall, __inline_isnormald, __inline_isnormalf, __inline_signbitl, __inline_signbitd, __inline_signbitf, __inline_isnanl, __inline_isnand, __inline_isnanf, __inline_isinfl, __inline_isinfd, __inline_isinff, __inline_isfinitel, __inline_isfinited, __inline_isfinitef, __darwin_fd_clr, __darwin_fd_set, __darwin_fd_isset, __darwin_check_fd_set, __sputc
ln -sf ../../../.ext/include/arm64-darwin22/rb_mjit_min_header-3.1.0.h include/ruby-3.1.0/arm64-darwin22/rb_mjit_min_header-3.1.0.h

結論

以下記事で解決。

M1 MacでRuby 2.4〜3.2をrbenvでビルドする最小限のセットアップを全部調べた

手順のコピペ

eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="$HOMEBREW_PREFIX/opt/bison/bin:$PATH"
export LDFLAGS="-L$HOMEBREW_PREFIX/lib"
export CPPFLAGS=""
export optflags=""
export OPENSSL_CFLAGS=""
export RUBY_CONFIGURE_OPTS=""

現在のBashのみで設定を変更するのがポイントっぽい?

このへんはネットの記事コピペしてやることが多いから、自分で解決できるようにならなきゃなぁと思いつつ・・・

このあと普通に

rbenv install 3.1.0

などで普通にインストールできた。