Mac で pod コマンドが通らなくなったときの対応
環境
Mac | |
---|---|
macOS | Catalina 10.15.7 |
Ruby | 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19] |
問題
pod update
しようとしたら通らず, 下記のようなエラーが出た。
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
原因
エラーにある通り、CocoaPods が使おうとしてる Ruby が見当たらないらしい。
CocoaPods が見ている Ruby のバージョンが 2.3 なのに対し, Catalina では Ruby のバージョンはデフォルトで 2.6 になっていた。(※)
そのため, Ruby に合わせて CocoaPods のバージョンを上げる必要がある。
※ Ruby のバージョンを確認するコマンドはこちら
ruby --version
解決手順
- ターミナルを開く
- gem をアップデートする
- 以下のコマンドを実行
$ sudo gem update --system -n /usr/local/bin
- 実行時のログ表示
Password: Updating rubygems-update Fetching rubygems-update-3.2.16.gem Successfully installed rubygems-update-3.2.16 Parsing documentation for rubygems-update-3.2.16 Installing ri documentation for rubygems-update-3.2.16 Installing darkfish documentation for rubygems-update-3.2.16 Done installing documentation for rubygems-update after 171 seconds Parsing documentation for rubygems-update-3.2.16 Done installing documentation for rubygems-update after 0 seconds Installing RubyGems 3.2.16 ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem
- 以下のコマンドを実行
- CocoaPods をアップデートする
- 以下のコマンドを実行
$ sudo gem install -v1.8.4 cocoapods -n /usr/local/bin
- 実行時のログ表示
Password: Fetching xxx.gem Successfully installed xxx Parsing documentation for xxx Installing ri documentation for xxx Done installing documentation for xxxs after xxx seconds xxx gems installed
- 以下のコマンドを実行
途中で困ったこと
CocoaPods をアップデートするとき, 最初は前述のものではなくバージョン指定なしのものを実行したらエラーが出た。
$ sudo gem install cocoapods -n /usr/local/bin
Password:
Fetching xxx.gem
Successfully installed xxx
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.15.0/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210414-17533-vtgrh5.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:
--xxx
/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:42: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.15.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.0/gem_make.out
律儀に mkmf.log ファイルも覗いてみたが, こちらはよく分からなかった。
似た症状を探した結果, 「バージョン指定なしで sudo gem install cocoapods -n /usr/local/bin
を叩くと ERROR: Failed to build gem native extension.
のエラーが出る」「Cocoapod のバージョンが新しすぎると, OS にデフォルトで入っているものよりも高いバージョンの Ruby が必要になる」ということだった。
現時点での Cocoapods の最新バージョンは 1.10.1 (2021/1/8) ではあるが, Cocoapods のバージョンに特にこだわりもなく動いてくれればよかったので, 調べていてよく見かけた 1.8.4 を指定して使ってみることにした。
備考
Catalina にしてから pod を使ってなかったため, pod コマンドが通らない状態になってるのに気づいていなかった。
OS アップデート時には環境を改めてチェックしといたほうが良さそう。
参考リンク
- CocoaPods 公式
https://github.com/CocoaPods/CocoaPods - High Sierra: bad interpreter #6898
https://github.com/CocoaPods/CocoaPods/issues/6898 - CocoaPods1.9.0 cannot install on Mojave10.14.6 #9568
https://github.com/CocoaPods/CocoaPods/issues/9568 - [Xcode]Mac OS Catalinaにアップデートしたらpodコマンドが通らなくなった
https://www.yukiiworks.com/archives/385 - pod install するとエラーが起きる時の対応
http://psychedelicnekopunch.com/archives/2302 - CocoaPodsのインストールで手間取ったこと
https://qiita.com/spring_i/items/181bc3c05142d1f80d93 - Cocoapodsがインストール出来ず、エラーが発生する
https://teratail.com/questions/243840
Discussion