Error - Fixing "Bad CPU type in executable" Error on M1 Mac

Fixing “Bad CPU type in executable” Error on M1 Mac

Step 1: Install Rosetta 2 (If Not Already Installed)
bash
# Check if Rosetta is needed (if this returns something, Rosetta is installed)

# Install Rosetta 2 if needed

Step 2: Clean Ruby Installation
# Remove existing Ruby installations

# Clean Homebrew Ruby and gems

Step 3: Install Ruby for ARM64
# Install Homebrew if not installed

# Add Homebrew to PATH for ARM64

# Install Ruby for ARM64

# Add the new Ruby to your PATH

Step 4: Install CocoaPods for ARM64

# Install CocoaPods

# Install ffi specifically for ARM64

Step 5: Configure Project
# Navigate to your project

# Clean existing pods

# Clean npm

# Reinstall dependencies

# Install pods (using ARM64 native installation)

Step 6: Update Podfile
Add these configurations to your Podfile:

Step 7: Environment Variables Setup
Add these to your
~/.zshrc or ~/.bash_profile:

# Ruby and CocoaPods paths

# Pod configurations

Troubleshooting Steps

1. If pod install still fails:
# Try with verbose logging

# Or try with repo update

2. If specific gems fail:
# Install with specific architecture

3. Check Ruby installation:
# Verify Ruby location

# Check Ruby version and architecture

4. Reset CocoaPods setup:
# Remove all CocoaPods caches

Important Notes

1. Architecture Verification:
- Use
file /usr/local/bin/pod to check pod binary architecture
- Use
file /usr/local/bin/gem` to check gem binary architecture

2. Xcode Configuration:
– Ensure Xcode is running natively on ARM64
– Check Build Settings > Architectures > Valid Architectures includes “arm64”

3. Common Issues:
– Always run pod commands from the ios directory
– Keep your Xcode installation up to date
– Consider using rbenv or rvm for Ruby version management

Updated on Oct 22, 2024