ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension


Have you been trying to install cocoapods on your Mac and getting this “failed to build gem native extension” error?

Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.

This is a common issue people face when trying to install gems on a Mac that doesn’t have a proper Ruby development environment. To make things worse, the cocoapods documentation recommends using the default Ruby that comes with macOS, and to use sudo gem install cocoapods. Both of those should be avoided.

Learn why you shouldn’t use the system Ruby to install gems on a Mac and why you should never use sudo to install gems.

The correct way to install cocoapods on a Mac

While there are various ways to install gems on a Mac, there’s really only one method that should be recommended: using a version manager.

I highly recommend using a Ruby manager because it allows you to have multiple versions of Ruby installed at the same time, and makes it easy to switch between them. Even if you’re using Ruby for the first time, it’s worth your time to learn how to use a Ruby manager because you will inevitably need one.

Over the past ten years, I’ve helped thousands of people set up Ruby on their Mac. It’s my specialty. From clean Macs to the most obscure issues, I’ve seen and fixed it all. And the most reliable solution is to use a version manager, specifically chruby.

To help people like you, and to make it as easy and painless as possible, I built Ruby on Mac, an automated script that will get you up and running with cocoapods in minutes.

Read what people say about the script.

It doesn’t just have a one-time use. You can run it over and over to keep your dev tools up to date and secure. And the next time you get a new Mac, it will save you a whole day because it can also automatically install all your Mac apps, fonts, macOS preferences, and GitHub repos, in addition to a complete development environment. You get all of these time savings now and in the future for a one-time cost.

If you’re trying to set up cocoapods on a work computer, you should be able to expense the one-time cost of Ruby on Mac.