Error installing jekyll: Failed to build gem native extension

Published by Moncef Belyamani on
Updated on

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 Jekyll on a Mac that doesn’t have a proper Ruby development environment. This particular error is usually due to one or more of these issues:

  • You’re using the version of Ruby that came preinstalled on your Mac (known as the system Ruby)
  • You have missing or broken development tools
  • You’re trying to install an old version of Jekyll on an Apple Silicon Mac.

To find out whether or not you’re using the system Ruby, run this command:

which ruby

If it says /usr/bin/ruby, then that’s the system Ruby on a Mac, and you definitely don’t want to be using it. Keep reading to understand why you shouldn’t use it, and what to do instead.

Failed to build gem native extension error installing Jekyll when using the system Ruby

Most people run into this issue after trying to install Jekyll using the system Ruby, either with the --user-install flag:

gem install jekyll --user-install

or with sudo:

sudo gem install jekyll

However, you should never use sudo to install gems.

Perhaps you initially tried to install Jekyll without sudo, using gem install jekyll, but then you got the infamous error you don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory:

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

You’ll get this error for any gem you try to install using the system Ruby. By default, it tries to install gems in the /Library/Ruby/Gems/2.6.0 directory, which is not meant to be modified, and is why Apple doesn’t give you permissions to write to it.

Here are more reasons why you shouldn’t use the system Ruby to install gems on a Mac.

Failed to build gem native extension error when installing Jekyll using a newer Ruby version

If you’re not using the system Ruby, and you know you have a proper Ruby dev setup with all the necessary tools, then the most likely cause of the “failed to build gem native extension” error when installing Jekyll is one or more outdated gems. If you’re seeing this issue when running bundle install in an existing Jekyll project, then I recommend updating any gems that are mentioned in the error. For example:

bundle update jekyll

Here are more resources that might be helpful:

So what’s the proper way to install Jekyll on a Mac?

Glad you asked! The most reliable method, and the only one I recommend, is to install a separate and newer version of Ruby using a version manager. If you’re really interested in all the possible options, including ones I don’t recommend (such as installing Ruby with Homebrew), read my definitive guide to installing gems on a Mac.

I highly recommend using a Ruby version 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 twelve years, I’ve helped hundreds of 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 and ruby-install.

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 asdf, frum, rbenv, 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 15 minutes or less with a single command
  • Spend an hour or more setting everything up manually

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

Ruby on Mac is the easiest, fastest, and most reliable way to set up and maintain a proper Ruby dev environment on a Mac. It can automatically fix your outdated or misconfigured development setup in minutes, saving you from having to wipe your computer. It also automatically installs all the other development tools you’ll need for Rails, Jekyll, Flutter, React Native, or any other project the depends on Ruby. It will save you so much time and frustration.

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

Read more about what makes Ruby on Mac special and how much people love 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.