Error installing json Ruby gem - ruby-on-rails

I'm running gem install json -v '1.8.1' however I get this error..
gem install json -v '1.8.1'
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170412-72871-wada1h.rb extconf.rb
creating Makefile
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/include/ruby-2.4.0/ruby/intern.h:795:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
generator.c:840:25: error: use of undeclared identifier 'rb_cFixnum'
} else if (klass == rb_cFixnum) {
^
generator.c:842:25: error: use of undeclared identifier 'rb_cBignum'
} else if (klass == rb_cBignum) {
^
1 warning and 3 errors generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1 for inspection.
Results logged to /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/extensions/x86_64-darwin-16/2.4.0/json-1.8.1/gem_make.out
When I run just gem install json it installs fine taking me over version 2 however I'm trying to install this https://github.com/peatio/peatio and it wants that version specifically.
Any other ideas?

Finding and updating the gem that is pulling in the JSON gem should work. However, another thing that worked for me was to update the version of JSON being installed.
bundle update json
This worked because it updated JSON to version 1.8.6 which is compatible with newer Rubies.

This seems to be a common issue with the json 1.8.1 gem. You can use a different version of json if you are declaring it explicitly, but in some cases, json 1.8.1 is a cascading dependency. For instance, you may see something like
In Gemfile:
rails was resolved to 4.1.5, which depends on
actionmailer was resolved to 4.1.5, which depends on
actionpack was resolved to 4.1.5, which depends on
actionview was resolved to 4.1.5, which depends on
activesupport was resolved to 4.1.5, which depends on
json
In this case, you just need to change the top level gem (in this case rails) to a different version. 4.2.6 works.

The issue is arise due to you are not in proper directory. Please go to your rails directory folder first then run this command like this:
rails#rails:~/rails_project/btc$ gem install json -v '1.8.1'
Then its work fine.

Related

Error installing gem bson_ext version 1.5.1

I am trying to set up a ruby 2.3.0 project in my system . Upon running bundle install , I am getting the following error :-
Fetching bson_ext 1.5.1
Installing bson_ext 1.5.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
/Users/admin/.rbenv/versions/2.3.0/bin/ruby -I /Users/admin/.rbenv/versions/2.3.0/lib/ruby/site_ruby/2.3.0 -r ./siteconf20201009-77301-z7iyto.rb
extconf.rb
checking for asprintf()... yes
checking for ruby/st.h... yes
checking for ruby/regex.h... yes
checking for ruby/encoding.h... yes
creating Makefile
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
make "DESTDIR=" clean
current directory: /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1/ext/cbson
make "DESTDIR="
compiling encoding_helpers.c
compiling cbson.c
cbson.c:118:36: warning: passing 'char *' to parameter of type 'const unsigned char *' converts between pointers to integer types with different sign [-Wpointer-sign]
result_t status = check_string(RSTRING_PTR(string), RSTRING_LEN(string),
^~~~~~~~~~~~~~~~~~~
/Users/admin/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:994:5: note: expanded from macro 'RSTRING_PTR'
(!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./encoding_helpers.h:26:44: note: passing argument to parameter 'string' here
result_t check_string(const unsigned char* string, const int length,
^
cbson.c:602:18: error: implicit declaration of function 'bson_buffer_get_max_size' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (length > bson_buffer_get_max_size(buffer)) {
^
cbson.c:602:18: note: did you mean 'bson_buffer_set_max_size'?
./bson_buffer.h:34:6: note: 'bson_buffer_set_max_size' declared here
void bson_buffer_set_max_size(bson_buffer_t buffer, int max_size);
^
1 warning and 1 error generated.
make: *** [cbson.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bson_ext-1.5.1 for inspection.
Results logged to /Users/admin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/bson_ext-1.5.1/gem_make.out
An error occurred while installing bson_ext (1.5.1), and Bundler cannot continue.
Make sure that `gem install bson_ext -v '1.5.1'` succeeds before bundling.
In Gemfile:
bson_ext
Changing the bson_ext version does not work . I specifically need version 1.5.1 for the project.
Please help !!!

Bundle install error json gem

I've got the following problem with ruby on rails v 5.1.6 (Ruby version 2.5.0), the most of the time I try to run the command bundle install on a rails project downloaded from github, I get the following error.
Fetching gem metadata from http://rubygems.org/..........
Using rake 0.8.7z
Using abstract 1.0.0
Using activesupport 3.0.7
Using builder 2.1.2
Using i18n 0.5.0
Using activemodel 3.0.7
Using erubis 2.6.6
Using rack 1.2.8
Using rack-mount 0.6.14
Using rack-test 0.5.7
Using tzinfo 0.3.37
Using actionpack 3.0.7
Using mime-types 1.23
Using polyglot 0.3.3
Using treetop 1.4.14
Using mail 2.2.20
Using actionmailer 3.0.7
Using arel 2.0.10
Using activerecord 3.0.7
Using activeresource 3.0.7
Using addressable 2.3.4
Fetching json 1.8.0
Installing json 1.8.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /home/daniele/.rvm/gems/ruby-2.5.0/gems/json-1.8.0/ext/json/ext/generator
/home/daniele/.rvm/rubies/ruby-2.5.0/bin/ruby -r ./siteconf20180512-28287-pzwgum.rb extconf.rb
creating Makefile
current directory: /home/daniele/.rvm/gems/ruby-2.5.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /home/daniele/.rvm/gems/ruby-2.5.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:0:
../fbuffer/fbuffer.h: In function ‘fbuffer_to_s’:
../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast
[-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
generator.c: In function ‘generate_json’:
generator.c:840:25: error: ‘rb_cFixnum’ undeclared (first use in this function)
} else if (klass == rb_cFixnum) {
^
generator.c:840:25: note: each undeclared identifier is reported only once for each function it
appears in
generator.c:842:25: error: ‘rb_cBignum’ undeclared (first use in this function)
} else if (klass == rb_cBignum) {
^
generator.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-tautological-compare’
Makefile:241: set di istruzioni per l'obiettivo "generator.o" non riuscito
make: *** [generator.o] Errore 1
make failed, exit code 2
Gem files will remain installed in /home/daniele/.rvm/gems/ruby-2.5.0/gems/json-1.8.0 for
inspection.
Results logged to
/home/daniele/.rvm/gems/ruby-2.5.0/extensions/x86_64-linux/2.5.0/json-1.8.0/gem_make.out
An error occurred while installing json (1.8.0), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.0'` succeeds before bundling.
In Gemfile:
airbrake was resolved to 3.1.12, which depends on
json
What Could the error be?
How can I fix it?
Thanks for helping.

Rails installation fails while running make nior4

I’m trying to install the current stable version of rails (5.2)
gem install rails
but it fails:
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /Users/ms1/.rvm/gems/ruby-2.4.1/gems/nio4r-2.1.0/ext/nio4r
[…]
compiling nio4r_ext.c
In file included from nio4r_ext.c:7:
./../libev/ev.c:488:48: warning: '/*' within block comment [-Wcomment]
/*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */
^
./../libev/ev.c:1068:26: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32]
[…]
fatal error: too many errors emitted, stopping now [-ferror-limit=]
9 warnings and 20 errors generated.
make: *** [nio4r_ext.o] Error 1
make failed, exit code 2
I’m on Mac OS X HighSierra (10.13.2) and I’ve installed Xcode (9.2) with developer / command-line tools (9.2), rvm 1.29.3, Homebrew 1.4.0, bundler 1.16.0, nokogiri 1.8.1.
I’m on ruby 2.4.1, but tried 2.4.2, 2.3.0, 2.2.2 as well, always with the same result.
Installing nio4r manually results in the same problem:
gem install nio4r
[…]
ERROR: Failed to build gem native extension.
Some answers on StackOverflow suggested
gem install nio4r -v '1.1.0' -- with-cflags="-std=c99"
which did not work, either.
Interestingly,
rails
gives me the following output on my machine:
Ignoring bigdecimal-1.3.2 because its extensions are not built.
Try: gem pristine bigdecimal --version 1.3.2
Rails is not currently installed on this system. To get the latest version, simply type: sudo gem install rails
Of course I tried both of the above mentioned hints, too; both result in the same problem as stated initially.
As I'm running out of ideas here and couldn't find any other helpful advice, I'm really looking forward for any ideas on this!
Filing an issue on nio4r's Github page solved my problem: There was an old port.h file from an abandoned Postgres installation in /usr/local/include/ on my system which was causing the trouble.
Removing /usr/local/include/port.h allowed me to install Rails!

How do I build "gem install json"?

I’m using Rails 4.2.7. I’m trying to build this tutorial — https://github.com/webguyian/bookstore, but getting a strange error, “An error occurred while installing json (1.8.0), and Bundler cannot continue.” So I tried “gem install json -v '1.8.0'”
localhost:bookstore-master davea$ gem install json -v '1.8.0'
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
/Users/davea/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20161007-50119-1huurrz.rb extconf.rb
creating Makefile
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/davea/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/intern.h:797:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ ( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/davea/.rvm/gems/ruby-2.3.0/gems/json-1.8.0 for inspection.
Results logged to /Users/davea/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-14/2.3.0/json-1.8.0/gem_make.out
I don’t know what this means or how to correct it. Any ideas?
The version of the json gem you are using is not compatible with Ruby >= 2.2. Please use at least version 1.8.2 of the json gem with Ruby 2.3.
See the Changelog for details about changes in functionality and compatibility.
That said, most of the time you don't even need an external gem to be able to work with JSON data in Ruby. The JSON module shipped with Ruby's standard library is fully functional and compatible with Rails already.

Could not find json-1.8.1 in any of the sources

I'm doing a project using react-rails but when I run
bundle install
I get
Could not find json-1.8.1 in any of the sources
Specifically, this is the entire error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
/Users/montana/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160629-5602-i1di2t.rb extconf.rb
creating Makefile
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/montana/.rvm/gems/ruby-2.3.0/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/montana/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/intern.h:797:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ ( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1
There's been various posts about this on stackoverflow, and have tried most "solutions' but none seem to work for me, I also ran
gem list | grep json
It says I have the json gem via
json (1.8.3)
multi_json (1.10.1)
I've tried to stop spring, updating the gems, & bundler. I've also ran
rbenv rehash
To no avail, still getting this error, any input would be highly appreciated.
I had a problem last time on Ubuntu, i tried to install this library and it worked as well.
sudo apt-get install libgmp3-dev
You can refer document at: Failed to build gem json native extension
You may want to lower down your ruby version or bump json version up. See: https://github.com/flori/json/issues/229
Had a quick look at json 1.8.1 gemspec and no mention of ruby 2.3.0 support as of today.

Resources