bundle install in your project root, then use bundle exec pod install or npx pod-install. Alternatively, reinstall CocoaPods with sudo gem install -n /usr/local/bin cocoapods to ensure the pod binary is in your PATH.Why this happens
This error occurs when the RubyGems environment cannot locate the CocoaPods gem executable (pod) for the current Ruby context. In the traceback, rubygems.rb:277:in 'find_spec_for_exe' fails because the gem specification for cocoapods is not activated in the load path.
Common causes:
– You installed CocoaPods globally with gem install but are running under a different Ruby version manager (RVM, rbenv, chruby) that doesn’t see that gem.
– Your project uses Bundler (a Gemfile/Gemfile.lock) but you haven’t run bundle install, so the bundled gems aren’t available.
– The pod binary was installed into a directory not on your PATH (common when using sudo gem install without -n /usr/local/bin).
The error message can't find gem cocoapods (>= 0.a) with executable pod is RubyGems’ way of saying “I know you want the pod command, but I can’t find a gem that provides it in the current environment.”
How to fix it
1. Use Bundler (recommended for React Native projects)
Most React Native templates include a Gemfile in the project root that pins CocoaPods. This ensures every contributor uses the same version.
# From your React Native project root
bundle install
Then run CocoaPods through Bundler so it uses the exact gem version from Gemfile.lock:
cd ios
bundle exec pod install
Or, from the project root, use the helper script that ships with React Native:
npx pod-install
npx pod-install runs bundle exec pod install inside the ios directory and handles the cd for you.
2. Reinstall CocoaPods with a proper executable path
If you prefer a global install (or have no Gemfile), uninstall the existing gem and reinstall it with the -n flag to place the pod binary in a standard location on your PATH.
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
The -n /usr/local/bin flag tells RubyGems to write the executable wrapper into /usr/local/bin, which is typically in $PATH for all shells. After this, pod --version should work from any directory.
3. Verify your Ruby version manager
If you use RVM, rbenv, or chruby, ensure the Ruby version you expect is active when you run pod.
# RVM
rvm use 2.7.5 --default
# rbenv
rbenv global 2.7.5
# chruby
chruby 2.7.5
Then reinstall CocoaPods for that Ruby:
gem install cocoapods
# or with bundler
bundle install
Run which pod to confirm the binary resolves to the expected Ruby installation.
How to prevent it
- Commit a
GemfileandGemfile.lockto your React Native repo so every machine runsbundle installand gets the same CocoaPods version. - Always run
podviabundle exec podornpx pod-installinside the project; avoid a globally installedpodthat may drift out of sync. - If you must install globally, use
sudo gem install -n /usr/local/bin cocoapodsonce and never mixsudo gemwith version-manager Rubies. - Keep your Ruby version manager (RVM/rbenv/chruby) initialized in your shell profile (
.zshrc,.bash_profile) so the correct Ruby is active in every terminal session.
FAQ
Why does pod --version work in some directories but not others?
Your shell’s PATH or the active Ruby version changes when you cd into a project that has an .ruby-version file (rbenv/chruby) or an .rvmrc (RVM). The directory where it works likely uses a Ruby that has CocoaPods installed; the project directory switches to a Ruby that doesn’t.
Should I use sudo with gem install?
Only if you’re installing into a system Ruby (e.g., /usr/bin/ruby) that requires root. With a version manager (RVM, rbenv, chruby), never use sudo; install gems into the user-managed Ruby instead.
What is npx pod-install and why does React Native recommend it?
npx pod-install is a small Node script added by the React Native template. It changes into the ios directory and runs bundle exec pod install, ensuring the correct Bundler context and CocoaPods version without you remembering the cd and bundle exec steps.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.