22

I've just set up a Linux Mint box for rails development with rvm. I went ahead and generated a Rails 5 app, set up the mysql connection, added the cucumber-rails gem and then tried to run:

rake cucumber

For some reason, I was met with:

/usr/bin/ruby2.3 -S bundle exec cucumber --profile default
/usr/lib/ruby/vendor_ruby/json/version.rb:3: warning: already initialized constant JSON::VERSION
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/version.rb:3: warning: previous definition of VERSION was here
/usr/lib/ruby/vendor_ruby/json/version.rb:4: warning: already initialized constant JSON::VERSION_ARRAY
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/version.rb:4: warning: previous definition of VERSION_ARRAY was here
/usr/lib/ruby/vendor_ruby/json/version.rb:5: warning: already initialized constant JSON::VERSION_MAJOR
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/version.rb:5: warning: previous definition of VERSION_MAJOR was here
/usr/lib/ruby/vendor_ruby/json/version.rb:6: warning: already initialized constant JSON::VERSION_MINOR
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/version.rb:6: warning: previous definition of VERSION_MINOR was here
/usr/lib/ruby/vendor_ruby/json/version.rb:7: warning: already initialized constant JSON::VERSION_BUILD
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/version.rb:7: warning: previous definition of VERSION_BUILD was here
/usr/lib/ruby/vendor_ruby/json/common.rb:99: warning: already initialized constant JSON::NaN
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/common.rb:99: warning: previous definition of NaN was here
/usr/lib/ruby/vendor_ruby/json/common.rb:101: warning: already initialized constant JSON::Infinity
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/common.rb:101: warning: previous definition of Infinity was here
/usr/lib/ruby/vendor_ruby/json/common.rb:103: warning: already initialized constant JSON::MinusInfinity
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/common.rb:103: warning: previous definition of MinusInfinity was here
/usr/lib/ruby/vendor_ruby/json/common.rb:128: warning: already initialized constant JSON::UnparserError
/var/lib/gems/2.3.0/gems/json-1.8.5/lib/json/common.rb:128: warning: previous definition of UnparserError was here

This is, to my knowledge, a fairly plain vanilla installation, so I cannot understand what I've done to earn these warnings. Do I somehow have conflicting gems in place? If so, how do I resolve this?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Micah Gideon Modell
  • 586
  • 1
  • 9
  • 24
  • Judging by the trace you are using globally installed ruby. Did you use rvm to install it globally? – Ivan Kolmychek Jan 14 '17 at 11:01
  • @IvanKolmychek, I've got the ruby package installed and I subsequently installed rvm. Ruby is available globally, yes. Am I answering your question? – Micah Gideon Modell Jan 14 '17 at 11:32
  • I get this issue too, but I don't have a solution. Doubt that globally installed Ruby is likely to be an issue - I'm using rbenv. – ttrmw Feb 19 '17 at 21:04
  • For the record, I did not ever find a solution, but rather proceeded with building a rails 4 app instead. I'll surely revisit one day-but not today – Micah Gideon Modell Feb 19 '17 at 22:53
  • I am getting this same error, thoughts on how to fix this? – Chris Hough Feb 26 '17 at 23:49
  • I'm getting this issue too, only when running rspec tests using guard, Rails 5 – redshift5 Mar 30 '17 at 03:40
  • Some gem in your Gemfile is depending on the `json` gem, but the `json` gem is probably also installed globally on your machine. Add the `json` gem to your Gemfile with `bundle add json`, run `bundle install` and these warnings should be gone. – J.R. Bob Dobbs Dec 27 '22 at 01:16

3 Answers3

39

I managed to get rid of the JSON warnings by:

bundle clean --force
bundle
redshift5
  • 1,966
  • 1
  • 18
  • 27
5

The json gem that came with your version of Ruby is a little outdated. If you want to get rid of these warnings, you have to include a more up to date version of it in your Gemfile:

gem 'json', '>= 2.0.0'

Then run bundle install.

Joost Baaij
  • 7,538
  • 3
  • 32
  • 34
4

redshift5's answer worked for me. Just to add more context.

I had this same issue while working on an application with Rails 6.

I was getting warnings like this:

/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/version.rb:4: warning: already initialized constant JSON::VERSION
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/version.rb:4: warning: previous definition of VERSION was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/version.rb:5: warning: already initialized constant JSON::VERSION_ARRAY
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/version.rb:5: warning: previous definition of VERSION_ARRAY was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/version.rb:6: warning: already initialized constant JSON::VERSION_MAJOR
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/version.rb:6: warning: previous definition of VERSION_MAJOR was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/version.rb:7: warning: already initialized constant JSON::VERSION_MINOR
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/version.rb:7: warning: previous definition of VERSION_MINOR was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/version.rb:8: warning: already initialized constant JSON::VERSION_BUILD
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/version.rb:8: warning: previous definition of VERSION_BUILD was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/common.rb:100: warning: already initialized constant JSON::NaN
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:130: warning: previous definition of NaN was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/common.rb:102: warning: already initialized constant JSON::Infinity
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:132: warning: previous definition of Infinity was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/common.rb:104: warning: already initialized constant JSON::MinusInfinity
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/json-2.5.1/lib/json/common.rb:134: warning: previous definition of MinusInfinity was here
/home/promisechukwuenyem/.rbenv/versions/2.7.2/lib/ruby/2.7.0/json/common.rb:129: warning: already initialized constant JSON::UnparserError

Things I tried:

  1. I tried removing my Gemfile.lock file and trying to do a fresh bundle install but that did not fix it.
  2. I tried to uninstall all gem versions of puma and jsonapi-serializer from my computer and reinstalling them, but that did not fix it.

Here's how I fixed:

First I ran the command below to force clean up unused gems in the bundler directory even if --path is set:

bundle clean --force

Next, I ran the command below to reinstall my gems for the project:

bundle install

OR

bundle update

OR

bundle update --force

That's all.

I hope this helps.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143