use cocoapods on M1 Mac

孙翔宇
2 min readFeb 2, 2021

what to do when google answer wont help and ffi is still making your time bleed

On the M1 Mac, binaries are compiled for arm64 architecture(refer to as ARM64 in the rest of this article). Currently, there is a problem that cocoapods will fail to run as one of its dependency ffi can not be built for ARM64 thus can not be load by cocoapods. This leads to the revamp of our ruby setup flow.

It includes reinstalling: homebrew, rbenv, ruby, cocoapods.

If the Google solution works. You don’t need to continue this article.

Example 1: a. arch -x86_64 gem install ffi b. arch -x86_64 gem install cocoapods c. arch -x86_64 pod install

Example 2: Under Rosetta do — gem install ffi b. gem install cocoapods c. pod install

Enable Rosetta for Terminal

  1. Under Applications/Utilities, you can find Terminal.
  2. Right-click then choose Get Info.
  3. Enable Open using Rosetta. Sequentially run the commands in the rest of the article

Homebrew

As in Install Instruction:

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon) so that you don’t need sudo when youbrew install. It is a careful script; it can be run even if you have stuff installed in /usr/local already. It tells you exactly what it will do before it does it too. You have to confirm everything it will do before it starts.

In our case, we will need to use the homebrew installed under /usr/local.

At this point, you have two sets of homebrew installed in your system. Check env to see which homebrew is exposed to the system. The default should be /opt/homebrew.

rbenv

Install Instruction

run /usr/local/homebrew/bin/brew install rbenv to install rbenv.

Install Ruby

example of setting a new global ruby rbenv install 2.7.2 && rbenv global 2.7.2

Even though homebrew have suggested you use RUBY_CONFIGURE_OPTS=” — with-openssl-dir=$(/opt/homebrew/bin/brew — prefix openssl@1.1) while install a ruby. In a reasonable world, we should always do this. But in our case, the system is using two sets of homebrews, and the one we want to use is not exposed to the system which creates uncertainty when later rbenv needs to know where is OpenSSL and readline. Here is the modified script we need.

We will use this modified script:

RUBY_CONFIGURE_OPTS="--with-readline-dir='$(/usr/local/homebrew/bin/brew --prefix readline)'" 
/usr/local/homebrew/Cellar/rbenv/1.1.2/bin/rbenv install 2.7.2

Notice how path being set for deadline and we want rbenv to install ruby with it’s won OpenSSL

Cocoapods

Depends if you installed ruby locally or globally. After it’s activated, In the iOS app directory where Gem file exists, run bundle install.

--

--

孙翔宇

Swift + Bujinkan + Taiji. “A teacher’s role is transform an ambitious student to an aspiring one. “