macOS ruby 3.x 설치 오류 해결방법

macOS m1에서 ruby 3.3을 설치할 때 아래와 같은 오류가 발생했다.

참고로 나는 mise 라는 개발환경 관리 툴을 쓰고 있다. (asdf와 비슷)

$ mise use -g ruby@3.3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  33.4M      0 --:--:-- --:--:-- --:--:-- 33.5M
*** Following extensions are not compiled:
psych:
	Could not be configured. It will not be installed.
	Check /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.j3yWlM/ruby-3.3.3/ext/psych/mkmf.log for more details.
BUILD FAILED (macOS 14.3.1 on arm64 using ruby-build 20240612)
You can inspect the build directory at /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.j3yWlM
See the full build log at /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.log
mise ~/Library/Caches/mise/ruby/ruby-build/bin/ruby-build failed
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.3.tar.gz...
-> curl -q -fL -o ruby-3.3.3.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  33.4M      0 --:--:-- --:--:-- --:--:-- 33.5M
==> Installing ruby-3.3.3...
ruby-build: using gmp from homebrew
-> ./configure "--prefix=$HOME/.local/share/mise/installs/ruby/3.3.3" --with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared --with-gmp-dir=/opt/homebrew/opt/gmp --with-ext=openssl,psych,+
-> make -j 10
*** Following extensions are not compiled:
psych:
	Could not be configured. It will not be installed.
	Check /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.j3yWlM/ruby-3.3.3/ext/psych/mkmf.log for more details.

BUILD FAILED (macOS 14.3.1 on arm64 using ruby-build 20240612)

You can inspect the build directory at /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.j3yWlM
See the full build log at /var/folders/yh/gx212std0x35b9r7pn_9gt440000gn/T/ruby-build.20240616131301.3912.log
mise ~/Library/Caches/mise/ruby/ruby-build/bin/ruby-build exited with non-zero status: exit code 1

설치 로그를 보면 아래와 같다

pkg_config: checking for pkg-config for yaml-0.1... -------------------- not found

DYLD_LIBRARY_PATH=.:../.. pkg-config --exists yaml-0.1
package configuration for yaml-0.1 is not found
--------------------

find_header: checking for yaml.h... -------------------- no

DYLD_LIBRARY_PATH=.:../.. "clang -o conftest -I../../.ext/include/arm64-darwin23 -I../.././include -I../.././ext/psych -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/opt/my>
ld: warning: ignoring duplicate libraries: '-lpthread'
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

DYLD_LIBRARY_PATH=.:../.. "clang -I../../.ext/include/arm64-darwin23 -I../.././include -I../.././ext/psych -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/opt/mysql-client/i>
conftest.c:3:10: fatal error: 'yaml.h' file not found
#include <yaml.h>
         ^~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <yaml.h>
/* end */

--------------------

해결방법은 libyaml을 설치하면 된다.

brew install libyaml

rbenv/ruby-build 위키에 루비 설치의 전제 조건이 나와있으니 참고하자

참고로 맥은 아래 툴들이 설치되어 있어야 ruby-build를 사용할 수 있다

# install Xcode Command Line Tools
xcode-select --install
# install dependencies with Homebrew
brew install openssl@3 readline libyaml gmp