pod install 报错: can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

问题描述:

因使用 brew 安装工具导致 ruby 环境错乱, 执行 pod install 时报错提示找不到 gem 可执行文件

Traceback (most recent call last):
    2: from /usr/local/bin/pod:23:in `
' 1: from /Library/Ruby/Site/2.6.0/rubygems.rb:294:in `activate_bin_path' /Library/Ruby/Site/2.6.0/rubygems.rb:275:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
解决办法:
  1. 重新安装 ruby 环境(默认安装最新版本)
> rvm reinstall ruby --disable-binary
  • 运行结果
mruby-1.3.0 - #removing src/mruby-1.3.0 - please wait
mruby-1.3.0 - #removing rubies/mruby-1.3.0 - please wait
RVM does not have prediction for required space for mruby-1.3.0, assuming 150MB should be enough, let us know if it was not.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/jack/.rvm/rubies/mruby-1.3.0, this may take a while depending on your cpu(s)...
mruby-1.3.0 - #downloading 1.3.0, this may take a while depending on your connection...
mruby-1.3.0 - #extracting 1.3.0 to /Users/jack/.rvm/src/mruby-1.3.0 - please wait
mruby-1.3.0 - #compiling - please wait
mruby-1.3.0 - #installing - please wait
Install of mruby-1.3.0 - #complete
Required ruby-2.7.0 is not installed.
To install do: 'rvm install "ruby-2.7.0"'
  1. 重新安装 cocoapods
> gem install cocoapods
  • 运行结果:
Successfully installed cocoapods-1.9.3
Parsing documentation for cocoapods-1.9.3
Done installing documentation for cocoapods after 1 seconds
1 gem installed

再重新执行 pod installOK

  • Homebrew,是Mac OS X上的软件包管理工具,使用起来非常方便,安装任意软件包时 brew 会自动下载其依赖;
  • RubyGems 提供了ruby社区gem的托管服务,主要用于下载、安装使用 ruby 软件包
  • 平常 iOS 开发使用 cocoapods 等工具都是使用 gems 进行安装管理,当使用 brew 安装软件包时有可能因依赖导致 ruby 环境错乱,不建议混合使用(使用 brew 也可以安装 cocoapods 而且很方便)

你可能感兴趣的:(pod install 报错: can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException))