Error installing jekyll: Failed to build gem native extension

Published by Moncef Belyamani - Updated

Have you been trying to install Jekyll on your Mac and getting this 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. This particular error is usually due to missing or broken command line tools.

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 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 the gem was being installed using the version of Ruby that came preinstalled on your Mac, known as the system Ruby. You’ll get this error for any gem you try to install using the system Ruby.

The /Library/Ruby/Gems/2.6.0 directory is not meant to be modified, which is why Apple doesn’t give you permissions to write to it. On top of that, the version that comes with your Mac is super old, and you can’t upgrade it. Ruby 2.6 reached end of life in March 2022.

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. If you’re really curious about the other ways, read my definitive guide to installing gems on a Mac.

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.

Install Ruby with a version manager

At a high level, there are a minimum of five steps to a working Ruby environment on macOS with a Ruby manager:

  1. Install Homebrew (which will also install the prerequisite Apple command line tools)
  2. Install a Ruby version manager such as chruby and ruby-install (others include rbenv, asdf, and RVM)
  3. Configure the Ruby version manager
  4. Install a specific version of Ruby
  5. Switch to that version of Ruby

You have two options for performing those steps:

  • Have everything set up for you in minutes with a single command
  • Spend an hour or more setting everything up manually

Have everything set up for you in minutes with a single command

Ruby on Mac will automatically install Ruby with chruby, ruby-install, and all the other development tools you’ll need for Rails or Jekyll. 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 by simply typing “rom” to keep your system up to date and secure. And the next time you get a new Mac, the Ultimate version will save you an entire 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.

When you buy Ruby on Mac today, you’ll be supporting an independent developer, and if you need it for your job or business, you should be able to expense it.

Read what people say about Ruby on Mac.

Spend an hour or more setting everything up manually

If you haven’t yet tried to install Ruby or other development tools on your Mac, you should be able to get up and running with the basics by following my free step-by-step guide for installing Ruby on a Mac.

This is the manual equivalent of the “Basic” version of Ruby on Mac, minus the comprehensive troubleshooting guide. You’ll then need to manually install gems, and any other necessary dev tools.