Skip to content

CocoaPods on Apple Silicon (M1/M2)

Problem

When running CocoaPods on Apple Silicon Macs (M1/M2 chips), developers encounter a common error:

ruby
LoadError - dlsym(0x7f8926035eb0, Init_ffi_c): symbol not found

This 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.

The most effective solutions involve either using Homebrew to install a native ARM64-compatible Ruby environment or leveraging Rosetta for x86_64 compatibility.

The simplest and most reliable approach is to use Homebrew to manage both Ruby and CocoaPods:

bash
# Uninstall any existing CocoaPods installation
sudo gem uninstall cocoapods

# Install CocoaPods via Homebrew
brew install cocoapods

Homebrew Setup

If you don't have Homebrew installed, first install it with:

bash
/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:

bash
# 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 cocoapods

Solution 3: Using Rosetta for x86_64 Compatibility

If you prefer using the system Ruby with Rosetta:

bash
# Install ffi gem with Rosetta
sudo arch -x86_64 gem install ffi

# Run pod install with Rosetta
arch -x86_64 pod install

Time-Saving Alias

Add this alias to your shell configuration file:

bash
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:

bash
# 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 ethon

Troubleshooting Common Issues

Xcode Command Line Tools

Ensure Xcode command line tools are properly configured:

bash
# Set the active developer directory
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

# Accept Xcode license if prompted
sudo xcodebuild -license

Architecture Compatibility Errors

If you encounter architecture-related errors:

bash
# 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 cocoapods

Homebrew Configuration Issues

If Homebrew wasn't installed for ARM64:

bash
# 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:

bash
# 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 cocoapods

Conclusion

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.