Skip to content

Fix: Error: Failed to build gem native extension

  • by
  • 2 min read

As easy as programming has become recently, there are still bugs and errors that you won’t quite understand the first time you see them. Especially if you’re working on a language like R or Ruby on Rails, things can come up unexpectedly which can be rather surprising for new developers.

In this article, we’re talking about the “error: failed to build gem native extension” issue, its causes and what you can do to fix the problem. 

Also read: Top 7 Python IDEs and Text Editors for Data Science Applications


What causes the “error: failed to build gem native extension” issue?

The error is generally triggered by missing or broken command line tools when installing gems on a Mac without the proper Ruby development environment. Note that gem can’t be installed with the native version of Ruby that comes preinstalled with your Mac. As the base Ruby library directory isn’t meant to be modified, Apple doesn’t give users permission to change or write data in the folder. 

How Facebook's AI is trying to assist suicide prevention

How to fix the “error: failed to build gem native extension” issue?

The best way to fix this issue is to do a proper gem installation on your Mac. You first need to install a separate (and newer) version of Ruby on your Mac using a version manager and then use the new version to install Gem. We recommend using Homebrew as its the default package manager for macOS and will make installing tools easy. 

If you’re on a Linux-based system, the solution is usually this.

sudo apt-get install ruby-dev

Based on your Ruby version, you might also want to include a specific number in the aforementioned command. Additionally, you might also need to install make after downloading ruby-dev. You can do so by running this command.

sudo apt-get install make.

Also read: Apt-get command not found: 5 Fixes

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>