Can not install json gem with ruby 2.2.3 on Ubuntu - ruby-on-rails

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.)

Try running rvm implode and then following this guide http://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you/
I suspect RVM did not include the correct headers for you.

Related

Gem::Ext::BuildError: ERROR: Failed to build gem native extension for rails version 4.2.6

I have created new rails app and try to run bundle install it shows this error,
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/json-1.8.6/ext/json/ext/generator/usr/bin/ruby2.3 -r ./siteconf20170704-11395-12tpg5u.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.6 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out
An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6'` succeeds before bundling
Kindly send me some suggestions,Thanks in Advance.
If you have a Mac or Linux machine try the following command:
sudo apt-get install ruby-dev
If that fails, what is your output for:
gem install json -v '1.8.6'
(please copy and paste all the output).
Similar issue
I'm not sure what will fix it for Mac, but people had positive experiences with brew install ruby.
If anyone facing this error with Mac OS Big Sur, please update the ruby version to atleast 2.7. I am using rvm to resolve this issue.
First checked the ruby version and rvm list
if rvm not install then install rvm

Error installing json on windows 8.1

I have installed rails 4.2.3 and ruby 2.2.2p95 on windows 8.1 x64 . When I try to run "bundle install" the installation fails because of json -v 1.8.3. I already have json version 1.8.1 installed. When I run rubygems update command it does not get updated. If I try to individually run gem install json -v 1.8.3 or gem install json --platform=ruby --version=1.8.3 I get the following error.
ERROR: While executing gem ... (OptionParser::InvalidArgument)
invalid argument: -platform=ruby
C:\>gem install json --platform=ruby --version=1.8.3
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20150719-4308-1m86usl.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating generator-x64-mingw32.def
compiling generator.c
make: x86_64-w64-mingw32-gcc: Command not found
make: *** [generator.o] Error 127
make failed, exit code 2
Gem files will remain installed in C:/Ruby22- x64/lib/ruby/gems/2.2.0/gems/json-1
.8.3 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0
/json-1.8.3/gem_make.out
Looks like you might have the 32-bit DevKit installed instead. Try uninstalling the DevKit you have and downloading and re-installing the latest 64-bit one. For more detail check out this similar answer:
https://stackoverflow.com/a/16579088/4034665
Try this gem install --verbose json -v 1.8.3. This should install the gem.

Error Installing JSON 1.8.1 via RubyGems

My OS is Windows 7 64x Ultimate. I try to install the json gem like this:
gem install json -v '1.8.1'
But I have a problem:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe -r ./siteconf20150220-2012-1uff8mn.rb extconf.rb
creating Makefile
make clean
Makefile:165: *** target pattern contains no `%'. Stop.
make
Makefile:165: *** target pattern contains no `%'. Stop.
make failed, exit code 2
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.
1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/js
on-1.8.1/gem_make.out
How can install json 1.8.1?
This seems to be a known bug with Rubygems. Take a look at the issue page for this bug over on github.
It has not yet been fixed but will hopefully be fixed soon. For now, it seems most people have to downgrade to rubygems 2.3.0 to get it to work on Windows. That should solve your problem.
You have to update your ruby gem to the newest version
To check what your ruby in now
$Ruby -v
Update it to ruby version 2.3.7
$rvm list known
$rvm install 2.3.7
$rvm use 2.3.7 --default
$gem install bundler
Check out this video https://www.youtube.com/watch?v=lsNXc3uQ2AA&lc=z22pvls4asawvhi5004t1aokgq0e4p2vb1qpp3w3z252bk0h00410.1528974099408204
Let me know if does that help!

Rails – Bundle install problems with json

I'm running OS X Mavericks, with Rails 3.2.12. When I try to do rails new project, it gets stuck at bundle install.
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
creating Makefile
make
compiling generator.c
make: gcc-4.2: No such file or directory
make: *** [generator.o] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/json-1.8.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
I get the same error when I do 'gem install json....' as it suggests. I've installed the latest version of Xcode, with the command line tools. When I do:
which gcc
I get:
/usr/bin/gcc
I'm new to all this stuff really, so please try to keep things simple.
So, prior to XCode 5, there was a gcc-4.2 binary, which got removed in the upgrade.
I found this tutorial helpful in getting gcc-4.2 back and running with ruby. It assumes that you're using homebrew to manage packages on your Mac.

Error installing rails, failed to build gem native extension

I know there is a couple of topics about that, but the reason I create a new one is that it still doesn't work for me ...
So here is my configuration :
ruby -v : 1.8.7
gem -v : 1.8.21
And when I try to make
sudo gem1.8 install rails
I have the following error :
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
creating Makefile
make
sh: make: not found
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/json-1.6.6 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/json-1.6.6/ext/json/ext/generator/gem_make.out
I'm running on Debian 6.0.4 Squeeze.
Thanks in advance for your answers !
You don't have make command, as your output says. In debian install package build-essential
I think gcc or c-compiler isn't install or not writen in environment path, I've got same problem while installing rails, but after Install gcc, I can install rails very well.

Resources