CocoaPods on M1 Mac
If you try to install Pods on a “clean” macOS, you’ll be greeted with a lovely load error. The only solution is to install Ruby yourself, built specifically for arm64.
This post is a rewritten response to How to run CocoaPods on Apple Silicon (M1). The correct answer wasn’t marked as the solution, and few people bother to look further when the first answer works.
Error During Pods Installation
If you try to install Pods on a "clean" macOS, you’ll encounter a lovely load error. This happens because the Ruby version included with the system was compiled for the x86_64 architecture under a universal build. To make matters worse, Ruby will soon disappear from macOS altogether:
WARNING: This version of ruby is included in macOS for compatibility with legacy software.
In future versions of macOS the ruby runtime will not be available by
default, and may require you to install an additional package.
The only solution is to install Ruby yourself, specifically built for arm64.
The process described below uses the default Homebrew paths. If you’re using a custom setup, replace /opt/homebrew with the result of brew --prefix
.
Installing Ruby with Homebrew
Let’s start by installing and configuring Ruby:
brew install ruby
After installation, Homebrew will notify you that the binaries have been placed in /opt/homebrew/lib/ruby/gems/3.1.0/bin (the exact version path may vary):
By default, binaries installed by gem will be placed into:
/opt/homebrew/lib/ruby/gems/3.1.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
Add the paths for Ruby and Gems to .zshrc, .zprofile, or .bashrc:
export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.1.0/bin:$PATH"
Afterward, either reload your shell settings or restart the terminal.
Once this is done, verify that the Ruby version being used is the newly installed one. The path should point to /opt/homebrew/opt/ruby/bin/ruby:
$ which ruby
/opt/homebrew/opt/ruby/bin/ruby
Installing CocoaPods
With the correct Ruby version in place, proceed to install CocoaPods:
gem install cocoapods
Again, verify the paths, this time for Pods. The path should point to /opt/homebrew/lib/ruby/gems/3.1.0/bin/pod:
$ which pod
/opt/homebrew/lib/ruby/gems/3.1.0/bin/pod
Installing Pods
After making these adjustments, running pod install
should no longer throw errors, and the Pods will install successfully:
$ pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.