CocoaPods on Apple Silicon (M1/M2)
Problem
When running CocoaPods on Apple Silicon Macs (M1/M2 chips), developers encounter a common error:
LoadError - dlsym(0x7f8926035eb0, Init_ffi_c): symbol not foundThis occurs because CocoaPods relies on Ruby gems that use native extensions, particularly the ffi gem, which may not compile correctly for the ARM64 architecture used by Apple Silicon processors. The macOS system Ruby (version 2.6) was built for universal binaries but has configuration issues that prevent proper compilation of native extensions.
Recommended Solutions
The most effective solutions involve either using Homebrew to install a native ARM64-compatible Ruby environment or leveraging Rosetta for x86_64 compatibility.
Solution 1: Install CocoaPods via Homebrew (Recommended)
The simplest and most reliable approach is to use Homebrew to manage both Ruby and CocoaPods:
# Uninstall any existing CocoaPods installation
sudo gem uninstall cocoapods
# Install CocoaPods via Homebrew
brew install cocoapodsHomebrew Setup
If you don't have Homebrew installed, first install it with:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Solution 2: Install Native Ruby via Homebrew
For more control over your Ruby environment:
# Install Ruby via Homebrew
brew install ruby
# Add Ruby to your PATH (add to ~/.zshrc)
echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH"' >> ~/.zshrc
# Reload your shell configuration
source ~/.zshrc
# Verify Ruby path (should point to Homebrew installation)
which ruby
# Install CocoaPods
sudo gem install cocoapodsSolution 3: Using Rosetta for x86_64 Compatibility
If you prefer using the system Ruby with Rosetta:
# Install ffi gem with Rosetta
sudo arch -x86_64 gem install ffi
# Run pod install with Rosetta
arch -x86_64 pod installTime-Saving Alias
Add this alias to your shell configuration file:
alias pod='arch -x86_64 pod'This allows you to run pod install normally while automatically using Rosetta.
Verifying Your Setup
After installation, verify your environment:
# Check Ruby version and path
which ruby
ruby -v
# Check CocoaPods installation
which pod
pod --version
# Verify ethon version (should be >= 0.13.0)
gem info ethonTroubleshooting Common Issues
Xcode Command Line Tools
Ensure Xcode command line tools are properly configured:
# Set the active developer directory
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
# Accept Xcode license if prompted
sudo xcodebuild -licenseArchitecture Compatibility Errors
If you encounter architecture-related errors:
# Check what architecture your Ruby is using
ruby -e "puts RbConfig::CONFIG['arch']"
# For universal binary installation with system Ruby
sudo env ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' gem install cocoapodsHomebrew Configuration Issues
If Homebrew wasn't installed for ARM64:
# Check Homebrew architecture
brew config
# Reinstall Homebrew for ARM64 if needed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Advanced: Using Ruby Version Managers
For projects requiring specific Ruby versions:
# Install rbenv
brew install rbenv
# Initialize rbenv
rbenv init
# Install a specific Ruby version
rbenv install 3.1.4
# Set global Ruby version
rbenv global 3.1.4
# Install CocoaPods
gem install cocoapodsConclusion
For most developers on Apple Silicon Macs, Solution 1 (installing CocoaPods via Homebrew) is the simplest and most reliable approach. It handles the architecture compatibility issues automatically and provides a clean installation.
If you work with multiple Ruby projects, Solution 2 with a Homebrew-managed Ruby or using rbenv provides better flexibility.
The Rosetta-based approach (Solution 3) remains useful for legacy projects or when you need to maintain compatibility with Intel-based systems.
System Ruby Deprecation
Note that Apple plans to remove Ruby from future macOS versions, making it essential to install your own Ruby environment for long-term compatibility.
Choose the solution that best fits your workflow and project requirements. All three approaches have been proven effective on Apple Silicon Macs.