4

I've been trying to figure out how to get the slack-ruby-client gem to work in my Ruby script, but I'm having issues when it comes to json, apparently.

Here's what I'm getting:

[user:ubuntu:~/Documents]$ irb                                                                                                                  4:43PM/07.08
2.5.1 :001 > require 'slack-ruby-client'
Traceback (most recent call last):
       11: from /home/user/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
       10: from (irb):1
        9: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        8: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        7: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        6: from /home/user/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.11.1/lib/slack-ruby-client.rb:13:in `<top (required)>'
        5: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `require'
        4: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `each'
        3: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:91:in `block in require'
        2: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:1434:in `activate'
        1: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:2315:in `check_version_conflict'
Gem::LoadError (can't activate json-1.8.6, already activated json-2.1.0)
2.5.1 :002 > exit

I cannot uninstall json v2.1.0 for whatever reason. Although it says it uninstalled successfully when running gem uninstall json v2.1.0, it still shows up when I look at the list of gems and search for json.

[user:ubuntu:~/Documents]$ gem uninstall json -v 2.1.0                                                                                          4:45PM/07.08
Successfully uninstalled json-2.1.0
[user:ubuntu:~/Documents]$ gem list | grep -i json                                                                                              4:47PM/07.08
json (default: 2.1.0, 1.8.6)
multi_json (1.13.1, 1.11.2)

and then the error still persists. I've tried to manually install 1.8.6 to see if it would override the default, but nothing.

Any suggestions would be greatly appreciated.

Attempt #1

[user:~/Documents]$ gem uninstall json                                                                                                   2:52PM/07.09

You have requested to uninstall the gem:
        json-1.8.6

activesupport-4.2.4 depends on json (>= 1.7.7, ~> 1.7)
activesupport-4.2.3 depends on json (>= 1.7.7, ~> 1.7)
rdoc-4.2.0 depends on json (~> 1.4)
sdoc-0.4.2 depends on json (>= 1.7.7, ~> 1.7)
sdoc-0.4.1 depends on json (>= 1.7.7, ~> 1.7)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled json-1.8.6

[user:ubuntu:~/Documents/rubyscript]$ bundle install                                                                                             2:56PM/07.09
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 1.16.2
Fetching json 1.8.6
Installing json 1.8.6 with native extensions
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
[user:ubuntu:~/Documents/rubyscript]$ irb                                                                                                        2:56PM/07.09
2.5.1 :001 > require 'slack-ruby-client'
Traceback (most recent call last):
       11: from /home/user/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
       10: from (irb):1
        9: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        8: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        7: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        6: from /home/user/.rvm/gems/ruby-2.5.1/gems/slack-ruby-client-0.11.1/lib/slack-ruby-client.rb:13:in `<top (required)>'
        5: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `require'
        4: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:90:in `each'
        3: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:91:in `block in require'
        2: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:1434:in `activate'
        1: from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/specification.rb:2315:in `check_version_conflict'
Gem::LoadError (can't activate json-1.8.6, already activated json-2.1.0)
2.5.1 :002 > exit
[user:ubuntu:~/Documents/rubyscript]$ cat Gemfile                                                                                                2:56PM/07.09
source 'https://rubygems.org'

gem 'json', '=1.8.6'              
LewlSauce
  • 5,326
  • 8
  • 44
  • 91
  • This is the way that we can uninstall default gem.. https://stackoverflow.com/questions/20945110/how-can-i-remove-a-default-gem-want-to-uninstall-a-gem-1-7-7-version-of-json – GeekSquad-Chennai May 10 '19 at 15:54

3 Answers3

11

Please try

bundle exec rspec

or

bundle exec rake spec

Hope this helps!

Weekend Baf
  • 197
  • 2
  • 8
0

First, try uninstalling the gem altogether for all versions:

gem uninstall json 

Then install the specific version required, also make sure your Gemfile specifies a specific version for the gem:

gem 'json', '=1.8.6'

This should fix the issue

Palsri
  • 442
  • 4
  • 13
  • So I tried to do that, and it uninstalled successfully. Added a Gemfile, ran bundle install, and tried to run the script and ran into the same problem. Updated my post as well to reflect the output of this. – LewlSauce Jul 09 '18 at 19:57
  • Yep, I ran `gem uninstall json` and it uninstalled successfully. Updating post to show output of that too. Just to be clear too because I never use Gemfiles unless I clone a project that already has it. To use it, just simply have the Gemfile, put the source on top, include my gems, and the ruby script will look in the current folder for the Gemfile? Or is there another way I need to associate the script to the Gemfile? – LewlSauce Jul 09 '18 at 20:03
  • What version of slack-ruby client are you using – Palsri Jul 09 '18 at 20:09
  • I think I got it now. I guess I wasn't too sure how to associate a Gemfile with a Ruby script. I just assumed they would look in the folder for a Gemfile prior to running. Not 100% sure how it works. I followed this guide to avoid a Gemfile https://bundler.io/v1.16/guides/bundler_in_a_single_file_ruby_script.html and it works now. How do you actually associate the ruby script with a Gemfile? – LewlSauce Jul 09 '18 at 20:10
  • 1
    So specify the version here itself – Palsri Jul 09 '18 at 20:18
  • Yeah I think I was trying to figure out how to "properly" go from that to an actual Gemfile, lol. Thanks so much again though man! Much appreciated! – LewlSauce Jul 09 '18 at 20:20
  • I’m happy to help – Palsri Jul 09 '18 at 20:44
  • I tried this in terminal but am getting an error while running the command gem 'json', '=1.8.6' ,it says ERROR: While executing gem ... (Gem::CommandLineError) Unknown command json, Can anybody please help – Pavithra B Dec 10 '21 at 13:14
0

bundle exec rspec solved for me... in my case I was trying to run rspec in a docker container. Ruby 2.6