Home > other >  Cocoapods gem not being properly recognized on M1 Mac
Cocoapods gem not being properly recognized on M1 Mac

Time:06-11

I'm trying to run the React Native Environment Setup guide. Once inside the directory created by npx react-native init command, I try to install the cocoapods gem as instructed. It install successfully, and when I run which pod, I get

/Users/user/.rvm/rubies/ruby-2.7.4/bin/pod

The issue is when I try to run any pod commands, like pod -v or pod install. It behaves like I don't have that gem installed and outputs this:

Traceback (most recent call last):
    4: from /Users/user/.rvm/rubies/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'
    3: from /Users/user/.rvm/rubies/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'
    2: from /Users/user/.rvm/rubies/ruby-2.7.4/bin/pod:23:in `<main>'
    1: from /Users/user/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
/Users/user/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

I have no idea why I'm getting that. I see that the pod bin is inside the ruby-2.7.4/bin/ folder, and on the last line of the error above, it looks inside the ruby-2.7.4/lib/ruby/2.7.0/rubygems.rb. I don't understand how the gems are handled very well, so I'm not sure if that's related. I appreciate any help.

Machine: Mac Mini M1. OS: Mac OS Monterey 12.4. RVM version: 1.29.12.

CodePudding user response:

I figured it out. These are the steps I took:

  1. Skip the sudo gem install cocoapods command recommended in the docs. Since I use RVM, it would install the gem on the global Ruby instead of the project's one.
  2. When initializing the React Native project, the CLI will ask to install cocoapods. Hit ESC to cancel.
  3. Navigate inside the project folder, install the required Ruby version (if necessary) and run bundle install. It will install the required cocoapods version.
  4. After that, pod --help or pod install should work. Keep in mind the pod install should be executed from the ios/ folder inside your project.

Please notice that I didn't have to make anything specific to the M1 processor at this time. I just installed everything normally from my default arm64 terminal.

  • Related