Poul
Poul

Reputation: 3476

trouble installing ruby gem json on my mac

I get this warning when trying to install the json module via ruby gems.

Any ideas?

Mac-Mini poulh$ sudo gem install json

Password:

WARNING: File '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 /specifications/json-1.2.0.gemspec' does not evaluate to a gem specification

Building native extensions. This could take a while...

ERROR: Error installing json:

ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install json mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

Upvotes: 7

Views: 4183

Answers (4)

Hossein Mohammadi
Hossein Mohammadi

Reputation: 1473

For macs with M1 CPU run arch -arm64 bundle install

Upvotes: 0

Steven Soroka
Steven Soroka

Reputation: 19902

I agree that you should install your own ruby version and XCode developer tools, but in the scenario where you want to get it working for people who don't have these things installed, switch to the "json_pure" gem, which is a pure-ruby implementation (so not the fastest, but super compatible).

Require 'json' will use it automatically.

Upvotes: 1

Peter Brown
Peter Brown

Reputation: 51697

I'm running Snow Leopard and did not have a problem installing the JSON gem with the native version of ruby. It looks like that gem is being compiled from source. Did you install XCode developer tools from the OS X disc?

Upvotes: 1

Jonathan Julian
Jonathan Julian

Reputation: 12264

I think most Mac developers would recommend that you run your own version of ruby instead of the system version that shipped with the Mac. This will give you more control over versioning and avoid environment issues like the one you are experiencing.

This is amazingly easy to do using the Ruby Version Manager. You can install multiple versions of ruby (1.8.6, 1.8.7, 1.9.1) and switch between them with ease. As a side-effect of using rvm, you no longer will have to use sudo to install gems.

Upvotes: 2

Related Questions