Cocoapods のインストールが失敗し、Ruby のローカル バージョンを変更できません

概要

MacBook Pro、macOS Catalina 10.15.7

Cocoapods をインストールしようとすると 2 つの主な問題があります。1 つ目は、Ruby のバージョンを 2.7.5 に変更しようとするとエラーが発生します。グローバルには変更できますが、ローカルには変更できないためです。

user@MacBook-Pro-de-User / % rbenv versions      
  system
* 2.7.5 (set by /Users/user/.rbenv/version)
  mruby-3.0.0

user@MacBook-Pro-de-User / % ruby -v                   
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

user@MacBook-Pro-de-User / % sudo rbenv local 2.7.5    
Password:
/usr/local/Cellar/rbenv/1.2.0/libexec/rbenv-version-file-write: line 19: .ruby-version: Read-only file system

2番目の問題は、cocoapodsをインストールしようとするときです。

user@MacBook-Pro-de-User / % sudo gem install cocoapods
Password:
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.3/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20240111-988-w3p1cs.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-debug
    --disable-debug
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9:in `system_libffi_usable?'
    from extconf.rb:46:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.16.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.16.3/gem_make.out

mkmf.log:

"pkg-config --exists libffi"
| pkg-config --libs libffi
=> "-lffi\n"
"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib   -arch x86_64   -lruby.2.6   "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

また、 brew install Cocoapods を実行しようとしましたが、 llvm cmake –build でスタックします。 また、llvm だけをインストールしようとすると、次のようになります。

user@MacBook-Pro-de-User /usr % brew install llvm
    Warning: You are using macOS 10.15.
    We (and Apple) do not provide support for this old version.
    It is expected behaviour that some formulae will fail to build in this old version.
    It is expected behaviour that Homebrew will be buggy and slow.
    Do not create any issues about this on Homebrew's GitHub repositories.
    Do not create any issues even if you think this message is unrelated.
    Any opened issues will be immediately closed without response.
    Do not ask for help from Homebrew or its maintainers on social media.
    You may ask for help in Homebrew's discussions but are unlikely to receive a response.
    Try to figure out the problem yourself and submit a fix as a pull request.
    We will review it but may or may not accept it.
    
    ==> Fetching llvm
    ==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-core/a656e8d
    ######################################################################### 100.0%
    ==> Downloading https://github.com/llvm/llvm-project/releases/download/llvmorg-1
    Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/0f45ee25df06c0fb1fa6d0d6df4677a9487c4b95f1020855dc61f95b532eb9c0--llvm-project-17.0.6.src.tar.xz
    ==> cmake -G Ninja .. -DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld;lldb;ml
    ==> cmake --build . 

解決策

そこで私はここで私の問題の解決策を見つけました:Rubyのインストール。 Cocoapods のインストールに関する問題は、Ruby の古いバージョン (2.6.3) が原因で、ローカルで他のバージョンに変更できませんでした。おそらく、バージョンがインストールされているにもかかわらず、インストール中にエラーが発生したためです。インストールに関する問題は openssl のバージョンが原因で、インストールには正しいと思われる 1.1 ではなく 3.0 が使用されていました。 1.1 openssl バージョンをインストールし、その openssl バージョンで Ruby バージョンをインストールするだけで済みました。

brew install [email protected]
rvm install ruby-3.3.0 --with-openssl-dir=$(brew --prefix [email protected])