FlutterでiOSの開発環境構築時に少しエラーが出てハマったので、その時の対処方法を紹介します。
現象
CocoaPodsをインストールしようとするとエラーが発生する。
$ sudo gem install cocoapods /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Users/xxxx/dev in PATH, mode 040777 Fetching: concurrent-ruby-1.1.7.gem (100%) Successfully installed concurrent-ruby-1.1.7 Fetching: i18n-0.9.5.gem (100%) Successfully installed i18n-0.9.5 Fetching: thread_safe-0.3.6.gem (100%) Successfully installed thread_safe-0.3.6 Fetching: tzinfo-1.2.7.gem (100%) Successfully installed tzinfo-1.2.7 Fetching: activesupport-4.2.11.3.gem (100%) Successfully installed activesupport-4.2.11.3 Fetching: nap-1.1.0.gem (100%) Successfully installed nap-1.1.0 Fetching: fuzzy_match-2.0.4.gem (100%) Successfully installed fuzzy_match-2.0.4 Fetching: httpclient-2.8.3.gem (100%) Successfully installed httpclient-2.8.3 Fetching: algoliasearch-1.27.3.gem (100%) Successfully installed algoliasearch-1.27.3 Fetching: ffi-1.13.1.gem (100%) 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.3.0/gems/ffi-1.13.1/ext/ffi_c /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20200810-3603-xmhpxy.rb extconf.rb /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Users/xxxx/dev in PATH, mode 040777 mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h extconf failed, exit code 1 Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.13.1 for inspection. Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.13.1/gem_make.out
調べると、makeで失敗していてRubyのバージョンが古いのが原因のようです。
対処方法
以下の記事を参考にMacのRubyを最新にアップデートします。
shinsuke789.hatenablog.jp