How to address problems with Ruby, cocoapods and react-native CLI on M1 MacBooks
You may have come across issues with installing
Homebrew, or using anything that might require Ruby on your M1 Mac or MacBook.
I’ve personally come across this issue when using
react-native init to initialise a React Native application. It throws an error when trying to install the iOS dependencies because
cocoapod needs Ruby to work properly.
Ruby doesn’t work properly from the get-go due to a problem with the universal binary that Apple is configured
Ruby to use in Big Sur to work with the
ARM architecture and it still recognising the host CPU as
x86_64. Each binary needs a separate
rbconfig.rb configuration file which is not supported by the
rbconfig module and since Apple are intending to deprecate the
Ruby binary there’s no real solution to this. Here’s a work around.
First things first: head to the Apple developer download page to download and install the latest build of
Command Line Tools.
Once they’re both installed, open a terminal window and install
Rosetta2 with this command.
/usr/sbin/softwareupdate —install-rosetta —agree-to-license
Now we need to install a version of
Homebrew that will work with
ARM. Run this next.
arch -x86_64 /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
You can now use
brew in your terminal by running
arch -x86_64 brew install <PACKAGE NAME>
The next step is to install
ruby-build. Run this command.
arch -x86_64 brew install rbenv ruby-build
We now need to add some config to our
.zshrc file, open it by running
open ~/.zshrc in your terminal and then add the following to the bottom of the file:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix firstname.lastname@example.org)"export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
If you don’t have
Zsh already configured then follow this guide.
We’ve now completed the initial setup and can get into fixing the actual problem with
Ruby. At this…