MacOS Catalina 10.15下React Native的pod install失败及Ruby解释器错误求助
pod install on macOS Catalina 10.15 with React Native Hey there, I’ve dealt with this exact headache on Catalina before—let’s break down why this happens and how to fix it for good.
Why this error pops up
macOS Catalina removed the system-provided Ruby 2.3 that your React Native/CocoaPods setup is trying to reference. The path /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby no longer exists, hence the "bad interpreter" error.
Recommended Solutions
I’ll start with the most robust fixes (these prevent future Ruby-related issues too):
Option 1: Use rbenv to manage Ruby versions (my go-to)
rbenv is a lightweight tool that lets you switch between Ruby versions without messing with system files.
- Install
rbenvvia Homebrew:brew install rbenv - Initialize
rbenvso it loads in your terminal sessions:
Follow the on-screen instructions to add the required line to yourrbenv init~/.zshrc(Catalina’s default shell) or~/.bash_profile. - Restart your terminal or reload the config:
source ~/.zshrc - Install a Ruby version compatible with Catalina and CocoaPods (2.7.x works great):
rbenv install 2.7.6 - Set this as your global default Ruby:
rbenv global 2.7.6 - Verify the change with:
ruby --version - Reinstall CocoaPods to use the new Ruby:
gem install cocoapods - Head back to your React Native project’s
iosdirectory and run:pod install
Option 2: Install Ruby via Homebrew (simpler if you don’t need version switching)
If you don’t want a version manager, you can install Ruby directly with Homebrew:
- Install Ruby:
brew install ruby - Update your shell’s
PATHto prioritize Homebrew’s Ruby over the system one. Open~/.zshrcin a text editor and add this line at the top:export PATH="/usr/local/opt/ruby/bin:$PATH" - Reload the config:
source ~/.zshrc - Check your Ruby version to confirm it’s the Homebrew one:
ruby --version - Reinstall CocoaPods and run
pod installas above.
Option 3: Quick temporary fix (not recommended long-term)
If you need a quick workaround (but this might break other tools later), you can update the script that’s calling the old Ruby path:
- Find the path to your current working Ruby with:
which ruby - Locate the script throwing the error (usually a CocoaPods or React Native script in your project’s
iosdirectory) and open it in a text editor. - Replace the shebang line at the top (looks like
#!/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby) with the path you got fromwhich ruby. - Save the file and try
pod installagain.
Extra Tips
- If you run into permission errors, avoid using
sudo—the version manager or Homebrew methods should install Ruby/CocoaPods in your user directory, so sudo isn’t needed. - If
pod installstill acts up, try cleaning your CocoaPods cache first:pod deintegrate pod install
Let me know if any of these steps hit a snag—I can help troubleshoot further!
内容的提问来源于stack exchange,提问作者Sagar Kachhadiya

