Running CocoaPods on Apple Silicon (M1) Running CocoaPods on Apple Silicon (M1) ios ios

Running CocoaPods on Apple Silicon (M1)


Still working in September 2021

#1 Install ffi

sudo arch -x86_64 gem install ffi

#2 Re-install dependencies

arch -x86_64 pod install


EDIT: I recently disabled Rosetta, and Cocoapods runs just fine with the addition of the ffi gem.

For anyone else struggling with this issue, I just found a way to solve it. In addition to running terminal in Rosetta:

  1. Right-click on Terminal in Finder
  2. Get Info
  3. Open with Rosetta

I installed a gem that seems to be related to the symbol not found in the error:

sudo gem install ffi

After doing this, cocoapods runs as expected.


TL;DR:

  • Install your own version of Ruby with Homebrew / rbenv / RVM (e.g. brew install ruby)
  • Add it and the gems binaries to your PATH and make sure the new version is used with which ruby (should be /opt/homebrew/opt/ruby/bin/ruby instead of /usr/bin/ruby if installed with Homebrew)
  • Install CocoaPods with sudo gem install cocoapods (make sure ethon is at least version 0.13.0)
  • Run pod install

Detailed answer:

All answers suggesting using Rosetta / arch -x86_64 are workarounds and not quite solving the real issue that comes from the way RbConfig and the universal binaries work.

require 'rbconfig'OSVERSION = RbConfig::CONFIG['host_os']ARCH = RbConfig::CONFIG['arch']HOSTCPU = RbConfig::CONFIG['host_cpu']BUILDCPU = RbConfig::CONFIG['build_cpu']TARGETCPU = RbConfig::CONFIG['target_cpu']puts "OS: #{OSVERSION}"puts "Arch: #{ARCH}"puts "Host CPU: #{HOSTCPU}"puts "Build CPU: #{BUILDCPU}"puts "Target CPU: #{TARGETCPU}"

If you call ruby on a file containing this code with the universal binary shipped with macOS, you will get the following result on an M1 Mac:

OS: darwin20Arch: universal-darwin20Host CPU: x86_64Build CPU: x86_64Target CPU: universal

As you can see, RbConfig was compiled for a « universal » CPU but built with an x86 CPU, and the rbconfig.rb file that was generated (see /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb) consequently uses invalid information for the host CPU.

As ffi uses information from RbConfig (see https://github.com/ffi/ffi/blob/dfae59e293974efaa7b4d414e5116d7a2187a06e/lib/ffi/platform.rb#L61 and https://github.com/ffi/ffi/blob/e3f2cf9b82055709ddbeecbf77810f43438c4b64/spec/ffi/fixtures/compile.rb#L11), we end up with OP’s error message.

The solution is, therefore, to get a version of Ruby built specifically for arm64 by using either Homebrew, rbenv or RVM.

For Homebrew:

  • Execute brew install ruby
  • Add export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH to your .zshrc (you can find your Homebrew installation directory with $(brew --prefix) if needed)
  • Execute source ~/.zshrc or restart your shell
  • Make sure you are using the correct ruby binary by executing which ruby (should be $(brew --prefix)/opt/ruby/bin/ruby)
  • Install CocoaPods with sudo gem install cocoapods
  • Make sure you are using the correct pod binary by executing which pod (should be $(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod)
  • Make sure ethon is version 0.13.0 or more with gem info ethon, otherwise run sudo gem install ethon
  • Run pod install

Ruby won't come with future macOS versions by default

Moreover, it should be noted that ruby is still included in macOS only « for compatibility with legacy software », as evidenced by running irb -v, so this is probably a good opportunity to install your own version anyway:

WARNING: This version of ruby is included in macOS for compatibilitywith legacy software. In future versions of macOS the ruby runtimewill not be available by default and may require you to install anadditional package.

irb 1.0.0 (2018-12-18)

Sources: