Can not install json gem with ruby 2.2.3 on Ubuntu

I am going through a Rails tutorial and I'm not able to complete 'bundle install' due to a problem with the json gem. When I attempt to install it directly:

me@tru2:~/rails/hello_app$ gem install json -v '1.8.3'
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    /home/me/.rvm/rubies/ruby-2.2.3-dev/bin/ruby -r ./siteconf20150820-12793-qdkev7.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.so
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
make: *** [generator.so] Error 1

make failed, exit code 2

Gem files will remain installed in /home/me/.rvm/gems/ruby-2.2.3-dev/gems/json-1.8.3 for inspection.
Results logged to /home/me/.rvm/gems/ruby-2.2.3-dev/extensions/x86_64-linux/2.2.0/json-1.8.3/gem_make.out

As mentioned the ruby version is 2.2.3.

me@tru2:~/rails/hello_app$ ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

Running 'gem list' shows that json 1.8.1 is currently installed but something in the default Gemfile must require 1.8.3. A search showed many similar questions but no answers that got me past this issue. I have tried running with sudo and it appears to work but going back to me the issue is still there.


cannot find -lgmp means that it can't find the gmp library. Try running:

sudo apt-get install libgmp3-dev

https://github.com/flori/json/issues/253


Json 1.8.3 seems to have some issues with Ruby 2.2.3 (though I expect some future patches of Ruby will probably fix the problem). Downgrading Ruby to 2.2.2 worked for me.

(That said, so did sudo apt-get install libgmp3-dev, as @alf suggested - but if you're not able to do that, downgrading ruby might be a feasible alternative.)