1

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.

ntocampos
  • 122
  • 6
  • Does this answer your question? [React Native pod install failed on Apple Silicon (M1)](https://stackoverflow.com/questions/65917288/react-native-pod-install-failed-on-apple-silicon-m1) – Abe Jun 07 '22 at 03:11
  • I doesn't :( I tried using the homebrew `cocoapods`, but with no success. – ntocampos Jun 07 '22 at 15:52

1 Answers1

2

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.

ntocampos
  • 122
  • 6
  • "Since I use RVM, it would install the gem on the global Ruby instead of the project's one" But that suggests that RVM was installed incorrectly. The whole point of RVM is that you say `gem install` and the correct `gem` installs in the correct `ruby`. – matt Jun 07 '22 at 18:06
  • The thing is that when I run the `npx react-native init ` command, as recommended on the docs, it will try to install cocoapods automatically. At that point, if I didn't have the project's Ruby version installed (currently 2.7.4, and I didn't since there was no way to know which version the generated project would use), the gem would be installed under the global version instead. That's why I needed to skip that automatic installation, install the correct Ruby, and then run `bundle install` after that. – ntocampos Jun 10 '22 at 13:34