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


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

Building native extensions. This could take a while...
ERROR: Error installing jekyll:
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. Most people run into this issue after trying to install Jekyll with sudo:

sudo gem install jekyll

However, you should never use sudo to install gems.

Perhaps you initially tried to install without sudo, using gem install jekyll, but then you got this write permissions error:

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory

That’s because macOS comes with Ruby preinstalled, but Apple doesn’t want you to make changes to the system Ruby, by installing gems for example.

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

So what’s the correct way to install gems 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. You might have seen instructions online to install Ruby directly with Homebrew, but that will eventually confuse you because you can only use one version at a time.

Over the past ten years, I’ve helped thousands of people set up Ruby on their Mac. 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 Jekyll in minutes.

Read what people say about the script.

Not only will Ruby on Mac set up a proper Ruby environment, it will also automatically install Jekyll, and all the other tools you’ll need for Jekyll, such as Bundler, Git, GitHub CLI, Node, and Yarn. All with a single command. It will save you so much time and frustration.

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 Jekyll on a work computer, you should be able to expense the one-time cost of Ruby on Mac.