DEV Community

Cover image for Fix a pod install error "undefined method 'exist' for File:Class" React Native
Davyd NRB
Davyd NRB

Posted on • Updated on

Fix a pod install error "undefined method 'exist' for File:Class" React Native

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"
Enter fullscreen mode Exit fullscreen mode

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. Make use of a Ruby version manager

1.1) In the root of your react native project, create a .ruby-version and Gemfile

.ruby-version:

2.7.8
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

1.3) Preinstalling ruby gems

cd your/rn_project/folder
rbenv local     # switch to 2.7.8 ruby version
bundler install # install gem deps
Enter fullscreen mode Exit fullscreen mode

Finally, execute the following command to install pods when necessary

cd ios; bundler exec pod install
# or
bundler exec pod install --project-directory=ios
Enter fullscreen mode Exit fullscreen mode

  1. 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
Enter fullscreen mode Exit fullscreen mode

Top comments (7)

Collapse
 
niyodusengaclement profile image
NIYODUSENGA Clement

You saved my day. Gracias

Collapse
 
edumazzucco profile image
Eduardo Mazzucco Cividini

Life saver, thank you so much!

Collapse
 
a7madgamal profile image
Ahmed Hassanein

"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

Collapse
 
retyui profile image
Davyd NRB

yes)

Collapse
 
tibbe profile image
Johan Tibell

Could you post a link to the React Native team recommendation?

Collapse
 
retyui profile image
Davyd NRB
Collapse
 
iamsoia profile image
Mykyta

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.