【Macbook M2】rbenv install でエラーとなった

問題

rbenv install でエラーとなった

Macbook Air M2

% rbenv install 2.7.1
To follow progress, use 'tail -f /var/folders/1c/d570n14x1lgd1rnbjjym49jm0000gn/T/ruby-build.20231013125948.85084.log' or pass --verbose
Downloading openssl-1.1.1w.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8
Installing openssl-1.1.1w...
Installed openssl-1.1.1w to /Users/asa/.rbenv/versions/2.7.1

Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...

WARNING: ruby-2.7.1 is nearing its end of life.
It only receives critical security updates, no bug fixes.


WARNING: ruby-2.7.1 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 13.5.2 using ruby-build 20231012)

Inspect or clean up the working tree at /var/folders/1c/d570n14x1lgd1rnbjjym49jm0000gn/T/ruby-build.20231013125948.85084.8BNwzF
Results logged to /var/folders/1c/d570n14x1lgd1rnbjjym49jm0000gn/T/ruby-build.20231013125948.85084.log

Last 10 log lines:
closure.c:264:14: error: call to undeclared function 'ffi_prep_closure'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
             ^
6 warnings and 1 error generated.
make[2]: *** [closure.o] Error 1
make[1]: *** [ext/fiddle/all] Error 2
make[1]: *** Waiting for unfinished jobs....
compiling new.c
linking shared-object -test-/string.bundle
make: *** [build-ext] Error 2

対応

環境変数RUBY_CFLAGSを指定してRubyをインストールする

RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.1
% RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.1
To follow progress, use 'tail -f /var/folders/1c/d570n14x1lgd1rnbjjym49jm0000gn/T/ruby-build.20231013130556.60148.log' or pass --verbose
Downloading openssl-1.1.1w.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8
Installing openssl-1.1.1w...
Installed openssl-1.1.1w to /Users/asa/.rbenv/versions/2.7.1

Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...

WARNING: ruby-2.7.1 is nearing its end of life.
It only receives critical security updates, no bug fixes.


WARNING: ruby-2.7.1 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew
Installed ruby-2.7.1 to /Users/asa/.rbenv/versions/2.7.1

asa@mba rails-multiple-db-sandbox % ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [-darwin22]

参考

https://github.com/ffi/ffi/issues/869

M1 Macでの開発環境構築(rosetta 無し)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA