It is advised to use Brew to install the arm version of
cocoapods for Apple M1/M2 chips.
brew install cocoapods pod install # fail: "undefined method 'exist' for File:Class"
In Ruby 3.2, "Fill.exists" was removed.
brew will automatically install the most recent version of
Ruby when you perform a
brew install cocoapods, which is why you encounter this problem.
There are two fixes I found—the first is advised by the React Native team, and the second is really quick but ugly!
1.1) In the root of your react native project, create a
source 'https://rubygems.org' # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version ruby File.read(File.join(__dir__, '.ruby-version')).strip gem 'cocoapods', '~> 1.12.1'
1.2) Install the Ruby version manager
brew install rbenv ruby-build # install ruby ver. manager rbenv init # load rbenv in your shell # ^^^follow instructions after re-run terminal!!! rbenv install 2.7.8 # install required Ruby version
1.3) Preinstalling ruby gems
cd your/rn_project/folder rbenv local # switch to 2.7.8 ruby version bundler install # install gem deps
Finally, execute the following command to install pods when necessary
cd ios; bundler exec pod install # or bundler exec pod install --project-directory=ios
- Hacky/Dirty way: Install cocoapods using an outdated version of Ruby:
# clean up brew uninstall --ignore-dependencies ruby --force brew uninstall cocoapods --force sudo gem uninstall cocoapods # install cocoapods brew install firstname.lastname@example.org brew install cocoapods --ignore-dependencies ln -s /email@example.com /opt/homebrew/opt/ruby
Top comments (5)
Life saver, thank you so much!
"There are two fixes I found—the first is really quick but ugly, and the second is advised by the React Native team!"
I think the order is reversed, right? :D
Could you post a link to the React Native team recommendation?