# Json ERROR: Failed to build gem native extension

**URL:** <https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565>\
**Category:** Rails\
**Created:** [May 28, 2011, 2:42am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565 "2011-05-28T02:42:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 28, 2011, 2:42am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/1 "2011-05-28T02:42:34Z")

</div>

I am quite new to rails and try now to set up a deployment  
environment. However I do not have the experience to over come every  
obstacle:

Centos 5.4 x86\_64  
apache 2.2.3  
rvm 1.6.13  
ruby 1.9.2-p0  
passenger 3.0.7  
capistrano 2.5.21

I have installed rvm as root. ruby 1.9.2-p0 installed and set as  
default.  
Installed passenger and adapted the apache config. Deployed the rails  
app  
with capistrano.

Then I pont the browser to [https://localhost.localdomain/reg](https://localhost.localdomain/reg)

The browser shows a passenger error:  
Ruby on Rails application could not be started  
Could not find json-1.5.1 in any of the sources (Bundler::GemNotFound)  
Backtrace:  
Frame 0:  
/usr/local/rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.13/lib/bundler/  
spec\_set.rb  
Frame 9:  
/usr/local/rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.7/lib/  
phusion\_passenger/utils.rb

when i go to the rails app and run  
bundle install  
it fails while building json:  
Installing json (1.5.1) with native extensions /usr/local/rvm/rubies/  
ruby-1.9.2-p0/lib/ruby/site\_ruby/1.9.1/rubygems/installer.rb:533:in  
`rescue in block in build\_extensions’: ERROR: Failed to build gem  
native extension. (Gem::Installer::ExtensionBuildError)

but $ gem install json  
installs 1.5.1 without a probelm

I do all this as root. It seems to me that there is a mix up of  
environments but do not know how to fix it. The error messge mentions /  
usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/site\_ruby/1.9.1/rubygems/  
installer.rb Why 191 and not 1.9.2 ?

xp:/var/www/html/registration/current# gem env  
/usr/local/rvm/rubies/ruby-1.9.2-p0/bin/gem:4: warning: Insecure world  
writable dir /var/www/html in PATH, mode 040777  
RubyGems Environment:

- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86\_64-linux]
- INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-1.9.2-p0
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-1.9.2-p0/bin
- RUBYGEMS PLATFORMS:
  - ruby
  - x86\_64-linux

- GEM PATHS:
  - /usr/local/rvm/gems/ruby-1.9.2-p0
  - /usr/local/rvm/gems/ruby-1.9.2-p0@global

- GEM CONFIGURATION:
  - :update\_sources =\> true
  - :verbose =\> true
  - :benchmark =\> false
  - :backtrace =\> false
  - :bulk\_threshold =\> 1000

- REMOTE SOURCES:
  - [http://rubygems.org/](http://rubygems.org/)

Generally how does one dignose the cause for Failed to build gem  
native extension, I was not able to find a log file to find out what  
went wrong.

Thank you  
Ernst

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 2:50am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/2 "2011-05-28T02:50:35Z")

</div>

On Fri, May 27, 2011 at 7:41 PM, eka [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Could not find json-1.5.1 in any of the sources (Bundler::GemNotFound)  
> it fails while building json:  
> Installing json (1.5.1) with native extensions /usr/local/rvm/rubies/  
> ruby-1.9.2-p0/lib/ruby/site\_ruby/1.9.1/rubygems/installer.rb:533:in  
> `rescue in block in build\_extensions’: ERROR: Failed to build gem  
> native extension. (Gem::Installer::ExtensionBuildError)
> 
> but $ gem install json  
> installs 1.5.1 without a probelm

After you do this and you then run ‘bundle install’ do you still get the  
error?

Also, are you using a gemset with rvm? And just to be sure have you  
confirmed your rvm settings with ‘rvm current’?

I do all this as root. It seems to me that there is a mix up of

> environments but do not know how to fix it. The error messge mentions /  
> usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/site\_ruby/1.9.1/rubygems/  
> installer.rb Why 191 and not 1.9.2 ?

I wondered about this in the past and dont know the answer but this as  
it  
should be.

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 3:20am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/3 "2011-05-28T03:20:17Z")

</div>

Running  
gem install json (which is sucessful)  
and then  
bundle install  
the same error occurs

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 4:36am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/4 "2011-05-28T04:36:08Z")

</div>

On Fri, May 27, 2011 at 8:19 PM, eka [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Running  
> gem install json (which is sucessful)  
> and then  
> bundle install  
> the same error occurs

I am not sure if this will work (also to answer your question, to  
diagnose  
‘failed to compile native extensions’, usually just google and tends to  
have  
either to do with the OS or access rights)… I am guessing your  
problem is  
related to either the location that the gem is getting installed or due  
to  
the OS (i.e. such as 32 vs 64 bit)… that said, try this at the command  
prompt and then try bundle install again:

rvmsudo gem install json

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 6:01am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/5 "2011-05-28T06:01:52Z")

</div>

Thank you David  
rvmsudo gem install json --\> ok  
bundle install --\> same error remains  
rvmsudo bundle install --\> same error remains

I wonder if there is a OS package missing. However if I run this not  
as root but in my own  
user login then it works which suggests the OS has all packages  
required.

It would be really helpfull if bundle install wrote to a log or stdout  
what is missing. I do not  
understand how the output of bundle install can be used to diagnose  
what went wrong.

bundle help  
shows there is a command viz to show dependencies.  
xp:/var/www/html/registration/current# bundle viz  
#\<LoadError: no such file to load – graphviz\>  
Make sure you have the graphviz ruby gem. You can install it with:  
`gem install ruby-graphviz`

After gem install ruby-graphviz it still gives the same LoadError

I think I make a wrong assumptions about execution environments and do  
not know enough.

Ernst

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 3:16am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/6 "2011-05-28T03:16:34Z")

</div>

On May 28, 10:49am, David K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > capistrano 2.5.21  
> > Ruby on Rails application could not be started  
> > bundle install  
> > error?  
> > Yes still same.
> 
> Also, are you using a gemset with rvm? And just to be sure have you  
> confirmed your rvm settings with ‘rvm current’?  
> Using defaults (as out of the box)  
> rvm current  
> ruby-1.9.2-p0

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [May 28, 2011, 2:45pm UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/7 "2011-05-28T14:45:09Z")

</div>

Tried  
gem install  
rvm gem install  
bundle install  
rvm wrapper ruby-1.9.2-p0

and in the end rebooted linux.

Now  
bundle install  
works and I get much further

Sorry I do not know why and how

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [June 5, 2011, 10:36pm UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/8 "2011-06-05T22:36:28Z")

</div>

I’m having this same problem, Mac OS X 10.6.7, running ruby-1.8.7-p334  
(using RVM)

When I run bundle install, all these bundles work fine until it gets to  
json , then it crashes. I tried different json versions 1.4.6 and 1.51  
– all execute “with native extensions” and it looks like that’s what  
makes it crash

Installing rake (0.9.0)  
Installing abstract (1.0.0)  
Installing activesupport (3.0.7)  
Installing builder (2.1.2)  
Installing i18n (0.5.0)  
Installing activemodel (3.0.7)  
Installing erubis (2.6.6)  
Installing rack (1.2.2)  
Installing rack-mount (0.6.14)  
Installing rack-test (0.5.7)  
Installing tzinfo (0.3.27)  
Installing actionpack (3.0.7)  
Installing mime-types (1.16)  
Installing polyglot (0.3.1)  
Installing treetop (1.4.9)  
Installing mail (2.2.19)  
Installing actionmailer (3.0.7)  
Installing arel (2.0.10)  
Installing activerecord (3.0.7)  
Installing activeresource (3.0.7)  
Installing addressable (2.2.2)  
Installing xml-simple (1.0.13)  
Installing aws-s3 (0.6.2)  
Using bundler (1.0.14)  
Installing columnize (0.3.1)  
Installing crack (0.1.8)  
Installing factory\_girl (1.3.2)  
Installing thor (0.14.6)  
Installing railties (3.0.7)  
Installing rails (3.0.7)  
Installing factory\_girl\_rails (1.0)  
Installing multipart-post (1.0.1)  
Installing faraday (0.5.3)  
Installing fastercsv (1.5.3)  
Installing json (1.4.6) with native extensions  
/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site\_ruby/1.8/rubygems/installer.rb:533:in  
`build\_extensions’: ERROR: Failed to build gem native extension.  
(Gem::Installer::ExtensionBuildError)

```
    /Users/jason/.rvm/rubies/ruby-1.8.7-p334/bin/ruby extconf.rb

```

checking for re.h… yes  
creating Makefile

make  
Makefile:128: warning: overriding commands for target  
`/Users/jason/Projects/' Makefile:122: warning: ignoring old commands for target`/Users/jason/Projects/’  
gcc -I.  
-I/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/i686-darwin10.7.0  
-I/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/i686-darwin10.7.0  
-I. -DHAVE\_RE\_H -D\_XOPEN\_SOURCE -D\_DARWIN\_C\_SOURCE -fno-common -g -O3  
-fno-common -pipe -fno-common -Wall -c generator.c  
generator.c:322: warning: ‘fbuffer\_free\_only\_buffer’ defined but not  
used  
cc -dynamic -bundle -undefined suppress -flat\_namespace -o  
generator.bundle generator.o -L.  
-L/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib -L. -lruby -ldl  
-lobjc

make install  
Makefile:128: warning: overriding commands for target  
`/Users/jason/Projects/' Makefile:122: warning: ignoring old commands for target`/Users/jason/Projects/’  
mkdir -p /Users/jason/Projects/  
mkdir -p (fb)/2/json/ruby/1.8/gems/json-1.4.6/ext/json/ext/json/ext  
/bin/sh: -c: line 0: syntax error near unexpected token `(' /bin/sh: -c: line 0:`mkdir -p  
(fb)/2/json/ruby/1.8/gems/json-1.4.6/ext/json/ext/json/ext’  
make: \*\*\* [(fb)/2/json/ruby/1.8/gems/json-1.4.6/ext/json/ext/json/ext]  
Error 2

Gem files will remain installed in /Users/jason/Projects/  
(fb)/2/json/ruby/1.8/gems/json-1.4.6 for inspection.  
Results logged to /Users/jason/Projects/  
(fb)/2/json/ruby/1.8/gems/json-1.4.6/ext/json/ext/generator/gem\_make.out  
from  
/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site\_ruby/1.8/rubygems/installer.rb:486:in  
`each' from /Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/installer.rb:486:in`build\_extensions’  
from  
/Users/jason/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site\_ruby/1.8/rubygems/installer.rb:159:in  
`install' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/source.rb:101:in`install’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/rubygems\_integration.rb:78:in  
`preserve_paths' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/source.rb:91:in`install’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/installer.rb:58:in  
`run' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:93:in`with\_build\_args’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/installer.rb:57:in  
`run' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/spec_set.rb:12:in`each’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/spec\_set.rb:12:in  
`each' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/installer.rb:49:in`run’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/installer.rb:8:in  
`install' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/cli.rb:222:in`install’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/task.rb:22:in  
`send' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/task.rb:22:in`run’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/invocation.rb:118:in  
`invoke_task' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/vendor/thor.rb:246:in`dispatch’  
from  
/Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/lib/bundler/vendor/thor/base.rb:389:in  
`start' from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/gems/bundler-1.0.14/bin/bundle:13 from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/bin/bundle:19:in`load’  
from /Users/jason/.rvm/gems/ruby-1.8.7-p334@global/bin/bundle:19

---

<div class="post-metadata">

**Author:** ![eka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eka](https://www.ruby-forum.com/u/eka)\
**Post date:** [June 6, 2011, 1:47am UTC](https://www.ruby-forum.com/t/json-error-failed-to-build-gem-native-extension/207565/9 "2011-06-06T01:47:23Z")

</div>

I figured this out – my project path had odd characters in it. The path  
of my app had a space and parenthesis in it – like so:

/Users/jason/Projects/MyApp (fb)/

this was messing up the native extension compile, it was hiccuping on  
this.
