安装 json 时出错:无法构建 gem 本机扩展

Error installing json: Failed to build gem native extension

花了一些时间弄清楚这个:

gem install json

导致此错误:

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

    /home/user/.rvm/rubies/ruby/bin/ruby -r ./siteconf20150611-1112-jqgxzj.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

这里重要的一行是"cannot find -lgmp"。

解决方案:

sudo apt-get install libgmp-dev