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 .ruby-version
and Gemfile
.ruby-version
:
2.7.8
Gemfile
:
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.13.0'
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 ruby@3.1
brew install cocoapods --ignore-dependencies
ln -s /opt/homebrew/opt/ruby@3.1 /opt/homebrew/opt/ruby
Top comments (7)
You saved my day. Gracias
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
yes)
Could you post a link to the React Native team recommendation?
sure
reactnative.dev/docs/environment-s...
Thanks a lot!
Spent half my day trying to get the project up and running on the new M2 Pro until I stumbled upon this article.