React Native Ruby Gems のインストール
概要
新しい React Native プロジェクトを作成するために npx react-native init Project を実行すると、次のエラーが発生します。
✔ Downloading template
✔ Copying template
✔ Processing template
✖ Installing Ruby Gems
error Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Fetching rexml 3.2.6
Installing rexml 3.2.6
Fetching CFPropertyList 3.0.6
Installing CFPropertyList 3.0.6
Fetching concurrent-ruby 1.2.2
Installing concurrent-ruby 1.2.2
Fetching i18n 1.14.1
Installing i18n 1.14.1
Fetching minitest 5.20.0
Installing minitest 5.20.0
Fetching tzinfo 2.0.6
Installing tzinfo 2.0.6
Fetching zeitwerk 2.6.11
Installing zeitwerk 2.6.11
Fetching activesupport 6.1.7.6
Installing activesupport 6.1.7.6
Fetching public_suffix 4.0.7
Installing public_suffix 4.0.7
Fetching addressable 2.8.5
Installing addressable 2.8.5
Fetching httpclient 2.8.3
Installing httpclient 2.8.3
Fetching json 2.6.3
Installing json 2.6.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
/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
./siteconf20230924-69529-n3hcgy.rb extconf.rb
creating Makefile
current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
make "DESTDIR=" clean
current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.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/MacOSX14.0.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/MacOSX14.0.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
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3 for
inspection.
Results logged to
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/extensions/universal-darwin-22/2.6.0/json-2.6.3/gem_make.out
An error occurred while installing json (2.6.3), and Bundler cannot continue.
Make sure that `gem install json -v '2.6.3' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
cocoapods was resolved to 1.13.0, which depends on
cocoapods-core was resolved to 1.13.0, which depends on
algoliasearch was resolved to 1.27.5, which depends on
json
✖ Installing Ruby Gems
error Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/environment-setup?os=macos&platform=android and follow the React Native CLI QuickStart guide for macOS and iOS.
info Run CLI with --verbose flag for more details.
brew install Cocoapods を使用して Cocoapod をインストールします。 ポッド –バージョン 1.13.0
brew install Cocoapods を使用して Cocoapod をインストールします。 ポッド –バージョン 1.13.0
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1/ext/ffi_c
/システム/ライブラリ/フレームワーク/Ruby.framework/バージョン/2.6/usr/bin/ruby -I /システム/ライブラリ/フレームワーク/Ruby.framework/バージョン/2.6/usr/lib/ruby/2.6.0 -r ./ siteconf20230924-70457-cgucg.rb extconf.rb *** extconf.rb が失敗しました *** 何らかの理由で Makefile を作成できませんでした。必要なファイルが不足している可能性があります ライブラリやヘッダー。詳細については、mkmf.log ファイルを確認してください。してもいいです 構成オプションが必要です。
/システム/ライブラリ/フレームワーク/Ruby.framework/バージョン/2.6/usr/bin/ruby -I /システム/ライブラリ/フレームワーク/Ruby.framework/バージョン/2.6/usr/lib/ruby/2.6.0 -r ./ siteconf20230924-70457-cgucg.rb extconf.rb *** extconf.rb が失敗しました *** 何らかの理由で Makefile を作成できませんでした。必要なファイルが不足している可能性があります ライブラリやヘッダー。詳細については、mkmf.log ファイルを確認してください。してもいいです 構成オプションが必要です。
この拡張機能がコンパイルに失敗した理由を確認するには、ここにある mkmf.log を確認してください。
/ライブラリ/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.16.1/mkmf.log
extconf が失敗しました。終了コード 1
Gem ファイルは検査のために /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1 にインストールされたままになります。 結果は /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.16.1/gem_make.out に記録されます。
解決策
Mac の Ruby バージョンをアップグレードする必要があります。そのために:
# install rbenv
$ brew install rbenv
# init rbenv bash
$ echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
$ source .zshrc
# find the latest stable version
$ rbenv install --list
# install the latest version
$ rbenv install 3.2.2
$ rbenv global 3.2.2
$ sudo gem install cocoapods
HTH