can't find gem cocoapods (Gem::GemNotFoundException) error happens when an existing pod binary on your PATH points to a Ruby environment where the cocoapods gem is missing. Fix it by reinstalling CocoaPods with brew reinstall cocoapods (and running brew link --overwrite cocoapods if /usr/local/bin/pod conflicts), or by reinstalling the gem with gem install -n /usr/local/bin cocoapods.Why this happens
When you run pod install in an Xcode project directory and see can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /usr/local/bin/pod, your shell is executing a leftover RubyGems wrapper script. That wrapper expects to find the cocoapods gem inside a specific Ruby installation—such as macOS system Ruby under /Library/Ruby/—but the gem files are no longer there.
This mismatch usually occurs for one of three reasons:
- A macOS system update: System updates can reset or relocate files in
/Library/Ruby/, removing previously installed gems while leaving the/usr/local/bin/podstub behind. - Switching Ruby managers or Homebrew: If you installed CocoaPods with
gemand later switched to Homebrew,rbenv,rvm, orasdf, your activepodbinary may still point to the old Ruby path. - An incomplete uninstall or upgrade: Removing a gem or interrupting an update can leave orphaned executables in
/usr/local/bin.
How to fix it
1. Reinstall CocoaPods with Homebrew (Recommended)
Homebrew bundles its own Ruby runtime for CocoaPods, which keeps it isolated from macOS system Ruby and prevents system updates from breaking your setup.
- Open Terminal and run:
brew reinstall cocoapods
- If you previously installed CocoaPods with
gem, Homebrew may fail during the linking step with an error like:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists.
- Preview the conflicting files before overwriting them:
brew link --overwrite --dry-run cocoapods
- If the list only shows stale CocoaPods stubs such as
/usr/local/bin/podand/usr/local/bin/xcodeproj, overwrite them with Homebrew’s symlinks:
brew link --overwrite cocoapods
- Refresh your shell’s command cache and verify the installation:
hash -r
which pod
pod --version
You should now be able to navigate to your Xcode project folder and run pod install.
2. Reinstall CocoaPods via RubyGems
If you prefer managing CocoaPods with RubyGems—or your project relies on a Ruby version manager like rbenv or rvm—uninstall the broken gem reference and reinstall it cleanly.
- Remove any existing
cocoapodsgem entries:
sudo gem uninstall cocoapods
- Reinstall CocoaPods into
/usr/local/bin, which avoids macOS System Integrity Protection restrictions on/usr/bin:
sudo gem install -n /usr/local/bin cocoapods
- If
sudo gem installfails withGem::CommandLineErroror you are using a user-owned Ruby installation (rbenvorrvm), omitsudo:
gem install -n /usr/local/bin cocoapods
If you are using rbenv or rvm, you can also run gem install cocoapods without the -n flag so the binary installs into your active Ruby manager’s shims directory.
- Run
pod installinside your project directory.
3. Check for multiple pod binaries on your PATH
Even after reinstalling CocoaPods, an older /usr/local/bin/pod stub can shadow a working installation in /opt/homebrew/bin/pod (on Apple Silicon Macs) or in your Ruby manager’s shim folder.
- List every
podexecutable your shell can see, in priority order:
which -a pod
- Check which Ruby environment is currently active:
which ruby
gem env
-
If the first path returned by
which -a podis an old stub you no longer use, remove it or adjust yourPATHin~/.zshrcso that Homebrew or your Ruby manager appears before/usr/local/bin. -
Open a new Terminal tab (or run
hash -r) and testpod --version.
4. Use Bundler for project-specific CocoaPods versions
If you work on an iOS or macOS team where different repositories require different CocoaPods versions, using Bundler avoids relying on a single global pod binary.
- Add a
Gemfileto the root of your Xcode project:
source "https://rubygems.org"
gem "cocoapods"
- Install the gem locally and run CocoaPods through Bundler:
bundle install
bundle exec pod install
Using bundle exec ensures RubyGems resolves cocoapods from the project’s Gemfile.lock rather than an arbitrary global stub.
How to prevent it
- Stick to one installation method: Choose either Homebrew (
brew install cocoapods) or a Ruby version manager with Bundler, and avoid mixingsudo gem installwithbrew. - Avoid installing gems into macOS system Ruby: System Ruby under
/Library/Ruby/is not meant for third-party development tools and can break after OS updates. - Pin CocoaPods in a
Gemfile: Runningbundle exec pod installkeeps teammates and CI machines on the exact same CocoaPods version. - Check
which -a podafter OS or Homebrew upgrades: Catching shadowed binaries early saves time whenpod installsuddenly fails.
FAQ
Why does pod install look in /Library/Ruby/Site after a macOS update?
The /usr/local/bin/pod stub was created when CocoaPods was installed against macOS system Ruby. When a macOS update modifies or clears system Ruby gem directories, the stub remains in /usr/local/bin and fails with Gem::GemNotFoundException because the underlying gem is gone.
Should I install CocoaPods with Homebrew or gem install?
For most solo developers, Homebrew (brew install cocoapods) is simpler because it manages its own Ruby dependency separately from macOS. If your team pins a specific CocoaPods version across projects, use a Ruby version manager (rbenv or rvm) paired with a Gemfile and bundle exec pod install.
How do I fix Could not symlink bin/pod when running brew link cocoapods?
This error means an older pod (and often xcodeproj) file already exists at /usr/local/bin/pod from a previous RubyGems install. Run brew link --overwrite --dry-run cocoapods to confirm only those stale stubs are affected, then run brew link --overwrite cocoapods to replace them.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
