How to Fix Cocoapods Install Errors on an Apple Silicon Mac

Are you getting this error when installing cocoapods?

"ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory."

Then you are in the right place, we are going to figure out how to fix CocoaPods install errors on an Apple Silicon Mac on this post and learn a thing or two.

Why do I need CocoaPods?

CocoaPod is a dependency manager that you use to install libraries for your Xcode Project. Google SDK are available as Pods and have been around for some time and is the preferred method by Google. Other options are manual download or by using the Swift Package Manager(SPM) to install the Google SDK as packages and the SPM is baked built-in on Xcode.

Cocoapods Install Command

Let’s, get started and install CocoaPods. Open up the Terminal app and type the following 

sudo gem install cocoapods

Running that command in a new Apple Silicon mac will throw the following ou’ll like end up with this error.

"ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory."

You’ll get this error for any gem you try to install on a Mac that hasn’t yet been properly configured for Ruby development.

MacOS comes preinstalled with Ruby, and the default location where gems would get installed is in the /Library/Ruby/Gems/2.6.0 directory. This preinstalled 2.6.6 version is outdated and the directory cannot be modified by the installation.

What is the fix?

The fix is to get the latest version of Ruby installed version installed in your machine.

At the time of this post writing the latest version of Ruby is currently 3.1.2. Check the main ruby website for the latest version.

How to install the latest Ruby?

To install the latest version of Ruby you can Ruby version manager (recommended)

You would need Homebrew installed for this. If you haven’t installed Homebrew please watch this tutorial.

How to Install Homebrew on Apple M1 Macs

If you already have homebrew installed, run the following command to install this two packages

brew install ruby-install chruby

From the brew installation summary you’ll be prompted to add the following to either your ~/.bash_profile or ~/.zshrc file.

Next open up the .zshrc file and update by adding the two chruby scripts and specify the ruby version.

source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.1.2

Next install the latest ruby from the Terminal.

ruby-install —-latest ruby

This installation would take some time. Once done, restart the Terminal.

From the terminal check the latest ruby version is installed correctly by the following command:

ruby —-version

Finally, when you try to install cocoapods from gem you should not get an error.

sudo gem install cocoapods

That should install with no errors.

Summary

There you go, we have learned following:

  • Why gem installation was failing
  • MacOS preinstalled ruby version is outdated
  • Ugrading the ruby version will fix the issue
  • Use a Ruby version manager package to install the latest version of Ruby
  • Using homebrew to install software on your machine
  • Installing ruby
  • Finally, running the gem install again to install CocoaPods

Checkout the video walkthrough from my channel and subscribe.

Check my previous post related to Cocoapod errors.

Leave a Reply

Your email address will not be published.