Fix: pod install Fails on Apple Silicon Mac with ffi Gem Error

Fix: pod install Fails on Apple Silicon Mac with ffi Gem Error

Written by

in

Quick answer: On Apple Silicon Macs, the system Ruby runs arm64 but the ffi gem CocoaPods depends on must be built for x86_64. Fix it by running sudo arch -x86_64 gem install ffi followed by arch -x86_64 pod install in your iOS project directory.

Why this happens

Apple Silicon Macs (M1, M2, M3) use the arm64 architecture. The system Ruby included with macOS Big Sur and later runs natively on arm64, but CocoaPods and several of its native gem dependencies—most notably ffi—have historically had compilation or runtime issues when built for arm64. When you run pod install without architecture flags, the gem installer tries to build ffi for arm64, which fails or produces a binary that CocoaPods cannot load, resulting in the error you see during dependency analysis.

The workaround is to force the gem installation and the pod command itself to run under Rosetta 2 (x86_64 translation layer) using the arch -x86_64 prefix. This ensures the ffi gem is compiled for Intel architecture, which CocoaPods expects.

How to fix it

1. Install the ffi gem for x86_64 architecture

Open Terminal and run:

sudo arch -x86_64 gem install ffi

You will be prompted for your administrator password. This command tells RubyGems to install the ffi gem using the x86_64 instruction set via Rosetta 2.

2. Run pod install under Rosetta 2

Navigate to your iOS project directory (the folder containing Podfile) and run:

arch -x86_64 pod install

CocoaPods will now execute using the x86_64 architecture, load the correctly built ffi gem, and complete dependency resolution and installation.

3. Alternative: Use Homebrew Ruby instead of system Ruby

If you prefer not to prefix every command with arch -x86_64, install a separate Ruby via Homebrew (which provides a native arm64 build that works with current CocoaPods versions):

brew install ruby

Then add Homebrew’s Ruby to your PATH in ~/.zprofile or ~/.zshrc:

export PATH="/opt/homebrew/opt/ruby/bin:$PATH"

Restart Terminal, then run gem install cocoapods and pod install normally. Modern CocoaPods (1.11+) and the Homebrew Ruby work natively on Apple Silicon without Rosetta.

How to prevent it

  • Use Homebrew Ruby for all Ruby gem work on Apple Silicon; it avoids system Ruby quirks.
  • Keep CocoaPods updated (gem install cocoapods or brew upgrade cocoapods)—newer versions have improved arm64 support.
  • Add an alias in your shell config if you must use system Ruby: alias pod='arch -x86_64 pod'.
  • Run pod install from Xcode’s Rosetta terminal when using Xcode built for Intel (rare since Xcode 12.3+ is universal).

FAQ

Why does this only happen on M1/M2/M3 Macs?

Intel-based Macs run x86_64 natively, so the system Ruby and all gems compile for the same architecture. Apple Silicon Macs run arm64 natively; the system Ruby is arm64, but older native gems like ffi have not been fully updated for arm64 compatibility, causing load failures when CocoaPods tries to use them.

Can I run pod install natively on Apple Silicon without Rosetta?

Yes, with CocoaPods 1.11 or later and a Homebrew-installed Ruby (or any arm64-compatible Ruby), pod install works natively. The arch -x86_64 workaround is only needed when using the system Ruby on macOS versions where the bundled gems are not yet arm64-ready.

What if I still get errors after the fix?

  • Ensure you are in the correct directory (the one containing Podfile).
  • Delete Podfile.lock and the Pods folder, then re-run arch -x86_64 pod install.
  • Verify Xcode Command Line Tools are installed: xcode-select --install.
  • If using React Native, confirm your node_modules are up to date (npm install or yarn install) before running pod install.
Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.