Error: Failed to Build Gem Native Extension on Mavericks

ERROR: Failed to build gem native extension on Mavericks

Also make sure that you've upgraded Xcode to re-install command line tools on Mavericks.
In terminal type:

xcode-select --install

Then follow the prompts.

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

Run following command

 brew cleanup -d -v 

Then run below command

brew install cocoapods 

Note: If you see failed to link then run brew link cocoapods

If linking is getting failed then run

brew link --overwrite cocoapods

This is how it get solved for me

For someone who is having m1 chip system they need to run this via Rosetta

select Terminal and press cmd(⌘)+I and check the "Open using Rosetta" option. ( For m1 chip based mac )

ERROR: Failed to build gem native extension (ruby extconf.rb): Mac OSX

Try this:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install <gemName>

For an explanation see this answer

Installing pg gem; ERROR: Failed to build gem native extension

Using homebrew fixed this for me:

gem uninstall pg
brew install apple-gcc42
gem install pg

EDIT: I also manually installed "devtools"

xcode-select --install

Can't install Rails on MacOs. Error messages: Failed to build gem native extensions

I have encountered a similar problem more than once.

I can think of three potential causes and solutions, though your problem may be rooted in something different.

1. Ruby version mismatch

You thought you were using Ruby 2.6.3. But actually the ruby your gem command recognises is a Ruby in a different version.
Check it out with ruby --version and make sure it is the right one.

If you have Rails in Ruby in a previous version, and if you have upgraded your Ruby since, then this type of error might be raised, depending on how your package management system handles the case.
If so, try uninstalling Rails first and reinstalling it.

2. Problem of installing Ruby

For some reason, the Ruby you are trying to use (2.6.3) has not been correctly installed. Then, a simple solution is to reinstall the Ruby, making sure it is correctly installed.

It highly depends which system you are using, but if you are using rbenv,

rbenv uninstall 2.6.3
rbenv install 2.6.3
rbenv rehash

should do the job. You can then reinstall your Rails.

3. Problem of permission (directory writing etc)

In your case, you run sudo gem install rails, and it probably means you have installed Ruby and Gems, including Rails, as the superuser while your Rails app directory is in a normal user.

I understand it is generally safer to install Ruby and Gems as the same user that runs Rails (mind you, though, it may not be impossible in practice in some specific environments). When the users are different, all sorts of permission problems can be encountered, and to install Rails apps are also problematic – it's possible but not straightforward in my experience.

So, my recommendation is, if ever possible and practical for you, to delete all the installed Ruby and reinstall it (=Ruby) as a normal user, who owns a Rails app directory, without using sudo. For example, if you are using rbenv, uninstall rbenv, delete all the directory related to rbenv, and reinstall rbenv from scratch as the normal user. Or, if you are using the system default Ruby, I'd recommend to install the Ruby-version management system, that is either rbenv or rvm, as the normal user, install Ruby(s) with it, and manage the installed Ruby versions with it.

If neither is possible or practical, check out the directory permission where Gems are installed and make sure they are consistent with what you would expect. Personally, I would make all the efforts to use a Ruby-version management system whenever I use Rails.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension Bcrypt-Ruby

I had the same problem which I solved by re-installing the XCode command line developer tools :

xcode-select --install
bundle install


Related Topics



Leave a reply



Submit