22

Using Ubuntu, when I run "bundle install" to set up my Rails environment, it throws an error during the JSON gem installation:

Installing json (1.7.3) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb 
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'

Gem files will remain installed in /home/danny/.bundler/tmp/2040/gems/json-1.7.3 for inspection.
Results logged to /home/danny/.bundler/tmp/2040/gems/json-1.7.3/ext/json/ext/parser/gem_make.out
An error occured while installing json (1.7.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.3'` succeeds before bundling.

When I try installing only the JSON 1.7.3 gem it also gives me an error:

Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'

Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.7.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out

I've installed RVM and am running Ruby 1.9.3; Why can't it install the JSON gem?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
TownWizard
  • 223
  • 1
  • 2
  • 5

1 Answers1

71

Installing the ruby1.9.1-dev package should fix this for you:

sudo apt-get install ruby1.9.1-dev
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • 1
    Not really, the "devkit" just sets up the hooks and options necessary to compile extensions which ask for it. The JSON gem uses [extensions written in C for speed](http://flori.github.com/json/doc/index.html). If you *really* don't want to (or can't) install the devkit, you can install the pure-ruby platform with `gem install json pure`. – wersimmon Jun 16 '12 at 01:31
  • 4
    Thank you! Wouldn't it be better to use `sudo apt-get install ruby-dev`, so that Ubuntu picks the appropriate version itself? – Simon Nov 27 '12 at 10:38
  • 3
    Yes and no. The "default" ruby for Ubuntu - even as recent as Quantal is 1.8 and many apps want 1.9 or better so you may have to specify in order to get the version you want rather than the default repository pacakge, which may be out of date. – RecentCoin Feb 14 '13 at 20:36
  • @Simon and RecentCoin Thank you, installing the wrong ruby-dev was a source of error for me. Only realized it after reading your comments. – Tobias Apr 03 '13 at 08:54
  • This didn't work for me but I didn't have build-essential apparently: $ sudo apt-get install build-essential – LuckyLuc Jan 21 '15 at 21:31