We recently upgraded one of our app to Ruby 2.2.2
Bundle installed failed ...... crying about well known issue of Error installing gem with native extension
, but this time for Gem json -v 1.8.3
Detailed error shows
Fetching: json-1.8.3.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20151209-13741-vqcxt1.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 /usr/local/rvm/gems/ruby-2.2.2/gems/json-1.8.3 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/json-1.8.3/gem_make.out
If you read the issue and log closely, you'll notice it says cannot find -lgmp
.
You can see that the linker can't find gmp
library or its missing on the server / machine on which you are bundling.
The machine on which I tried this is Ubuntu. So I tried to search gmp
library first using command
apt-cache search gmp
This results in few records as ...
> libgmp-dev - Multiprecision arithmetic library developers tools
> libgmp10 - Multiprecision arithmetic library libgmp10-doc -
> Multiprecision arithmetic library example code libgmp3-dev -
> Multiprecision arithmetic library developers tools libgmpxx4ldbl -
> Multiprecision arithmetic library (C++ bindings) libhogweed2 - low
> level cryptographic library (public-key cryptos) libnettle4 - low
> level cryptographic library (symmetric and one-way cryptos)
Now we just need to check if the development package is installed or not for gmp
library. Use command
dpkg -l | grep gmp
This results in few records as ...
> ii libgmp10:amd64 2:5.1.3+dfsg-1ubuntu1 amd64 Multiprecision arithmetic library
> ii libgmpxx4ldbl:amd64 2:5.1.3+dfsg-1ubuntu1 amd64 Multiprecision arithmetic library (C++ bindings)
If dev packages are not in the list, install them with following command
sudo apt-get install libgmp-dev libgmp3-dev
After that just run bundle install
or gem install json
again and it should work now.