enforcing a ruby gem version - ruby

I am completely new to ruby, don't know the 1st thing about rvm, gemset etc. Just forced to use a CLI tool (kensa by heroku) written in ruby and facing an issue.
The kensa tool seems to use a gem named rest-client. When I run it it throws an error:
/Users/shaharsol/.rvm/gems/ruby-2.4.2/gems/rest-client-1.8.0/lib/restclient/request.rb:163:in `fetch': key not found: :ciphers (KeyError)
Some searches suggest that v1.8 of rest-client is too old so I installed v2.0.2. Now when I do a gem list I get:
rest-client (2.0.2, 1.8.0)
When I run kensa again it still used to old version. So I went and modified it kensa.gemspec file (which is referred to from Gemfile) and to my best understanding told it to use the newer version:
s.add_runtime_dependency(%q<rest-client>, "~> 2.0")
Yet, when I run kensa again, it still uses the old rest-client 1.8.0!
What am I missing? What am I doing wrong? Or what else is required for the kensa to run with the new rest-client 2.0.2 ???
PS - If my problem doesn't relate at all to changing 1.8.0 => 2.0.2 please tell me what else to do. I really don't care which rest-client version kensa uses, I just need it to run!

To remove older version of the gem, you have two options:
# remove all versions of the gem
gem cleanup rest-client
After this, you can do 'bundle install' and only install the version you want.
# choose which one you want to remove
gem uninstall rest-client --version 1.8.0
After this, you will only have 2.0.2 version.
Hope this solves your problem.

Related

"Could not find activesupport" when 3 versions installed

I'm just trying to use the simple career_builder gem and just get it imported by running the simple script:
require 'career_builder'
puts 'Hello world!'
and yet get the following error: /Library/Ruby/Site/2.0.0/rubygems/dependency.rb:315:in 'to_specs': Could not find 'activesupport' (~> 2.3.5) - did find: [activesupport-4.2.1,activesupport-3.1.12,activesupport-3.0.3] (Gem::LoadError)
I installed the gem with gem install career_builder and ran bundle install and even updated activesupport to the most recent version, but for some reason, the program can't find the newer version of activesupport. Does the gem require version 2.3.5?
http://guides.rubygems.org/patterns/
The ~>or 'twiddle-waka' is a ruby gems shortcut to specify the earliest version of the gem you can use without letting you go up to the next major release.
Your gem is being a bit unorthodox and also specifying a patch level.
So the gem_specification you're working with (activesupport' (~> 2.3.5)) really means minimum version of 2.3.5 maximum of the last patch released before 2.4.0.
The activesupport versions you have installed are all for subsequent major releases and won't work. Install something between 2.3.5 and 2.4.0 and you should be good to go.
Yes. It does require Active Support version >= 2.3.5 and < 2.4.0. All of your Active Support versions are > 2.4.0.
~> is called the spermy operator. See Meaning of tilde-greater-than (~>) in version requirement?
The gem has not been updated in 4 years, so it uses Rails 2.
FWIW, I don't think you'll have much luck getting it to work, so you may want to find a similar gem that works with Rails 4 and has been updated within the last few months.

toy/doc undefined method 'available?'

I'm attempting to build local Ruby documentation as suggested here:
https://github.com/toy/doc
However when I use the default Rakefile I get the following:
[Documentation]$ rake build
configuring and updating: 100.0%
rake aborted!
undefined method `available?' for Gem:Module
/Users/snowcrash/.rvm/gems/ruby-2.0.0-p195/gems/sdoc-0.2.20/lib/sdoc/json_backend.rb:9:in `<top (required)>'
Any suggestions?
I don't know much about ruby (and even less about the gem ecosystem built up around it), but I believe a possible workaround for this issue is to find what gems the project requires and manually install them. In the case of this particular project, it looks like you need the gem "fspath".
At the project root, type
gem install fspath
and try re-running rake.
I honestly don't know the actual root cause of the issue, other than that presumably, your version of the 'gem' program is probably > v2, while some other program (rake?) expects it to be older and still support the "available?" method.
If installing "fspath" doesn't fix the issue, you could try downgrading your version of gem by doing
gem install -v [some version of gem older than v2]
Check gem install --help for more info on this.
This is just for future visitor who has the same issue.
As ekremkaraca said, you can just solve this by downgrading rubygems.
rvm install --force rubygems 1.4.2

Can I control the version of rubygems that IntelliJ uses?

I'm trying to start a rails application in IntelliJ with the Ruby plugin.
I've imported the application and set up the run configuration as best I can. When I try to run it I get the error:
NoMethodError: undefined method `version_requirements' for #<Gem::Dependency:0x7de21f45>
When looking for an answer I found this page saying that I should do this:
$ gem install rubygems-update -v='1.4.2'
$ gem uninstall rubygems-update -v='1.5.0'
$ update_rubygems
Since it's IntelliJ's ruby plugin that is managing the gems, I assume that I have to change the version of rubygems-update that the plugin is using.
Is this the right approach to take? And if so, can anyone tell me how to go about it?
I tried listing the gems but that gem is not shows so I must not be listing the gems in the right place, but I don't know where to look.
Many thanks :)
IntelliJ IDEA cannot handle it, you will need to install the appropriate rubygems version from the command line.
Note that your current rubygems-update version may be different, verify it with gem list and use the reported version when uninstalling.

Could not find gem 'rubytree (~> 0.5.2) ruby' while installing ChiliProject on Debian

I am trying to install chiliproject on a server, following the -well done- documentation I am hitting this error
Could not find gem 'rubytree (~> 0.5.2) ruby' in any of the gem sources listed in your Gemfile.
I did a gem install rubytree
I get this message
========================================================================
Thank you for installing rubytree.
WARNING: SIGNIFICANT API CHANGE in 0.8.0 !
------------------------------------------
Please note that as of 0.8.0 the CamelCase method names are DEPRECATED.
The new method names follow the ruby_convention (separated by '_').
The old CamelCase methods still work (a warning will be displayed),
but may go away in the future.
Details of the API changes are documented in the API-CHANGES file.
========================================================================
Successfully installed rubytree-0.8.1
1 gem installed
Installing ri documentation for rubytree-0.8.1...
file 'COPYING,API-CHANGES' not found
Installing RDoc documentation for rubytree-0.8.1...
file 'COPYING,API-CHANGES' not found
That is saying the installation was succesful. So why do I get the error ?
If the error is from the API change how can I request version 0.5.2 of the rubytree gem ?
When I do a gem list --local | grep 'rubytree'
I have this output rubytree (0.8.1)
So why is the system saying could not find gem 'rubytree' ?
thank you for any help,
Depending on what version of rails you are using (and it sounds like you are using a relatively newer one, if it's prompting you for your Gemfile), then you need to use Bundler to manage your gems.
Try editing your Gemfile, adding a new line that reads:
gem "rubytree", "< 0.6"
Then open up a console, and type this command
bundle install
This should fix your problems, but if you still get errors when running a command, then try typing bundle exec prior to the command (i.e. rails server becomes bundle exec rails server).
Currently, we require rubytree exactly in version 0.5.2 or 0.5.3, as specified in our Gemfile, the 0.8.1. version you installed by hand will not suffice that requirement, which is exactly what the error message states.
What seems a bit odd is the literal ruby in the error message. Could you please make sure that you have the exact unchanged Gemfile from the source on your system? Also, could you please remove any user-installed plugins and try again? Also, which ruby (type and version) on which operating system are you using?

Ruby Twitter gem

-- UPDATE --
Ok its fixed. This is what I did. remove all ruby and rubygems completely. then install ruby1.9.1-full and rubygems1.9.1 then install the twitter gem.
Hi guys,
I am having trouble working with the Twitter gem. I am using ruby 1.8.7
After installing when I try to run a simple script I get this error
ruby twitter.rb
./twitter.rb:5: uninitialized constant Twitter (NameError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from twitter.rb:2
I running this on a Ubuntu box. I checked with gem -list and I see the Twitter (1.1.0) is listed there.
this is the code I am trying to run
require "rubygems"
require 'twitter'
puts Twitter.user_timeline("test").first.text
Any ideas ?
I believe it only works with Ruby 1.9 If you want to use twitter gem try version 0.9 with Ruby 1.8.x
This works for me:
ruby-1.9.2-p0 > require 'twitter'
=> true
ruby-1.9.2-p0 > puts Twitter.user_timeline("test").first.text
TExES Pedagogy and Professional Responsibilities EC-12 Teacher Certification Test Prep Study Guid… - by Sharon A Wynne http://amzn.to/f3kF74
=> nil
which version of ruby are you using?
gouravtiwari21's comment seems to fix the problem, but it's wrong to suggest that the twitter gem requires 0.9.0 if you want to run it using Ruby 1.8.x.
You can check out the version compatibility here:
http://travis-ci.org/#!/jnunemaker/twitter
It shows the twitter gem working with Ruby installs as low as 1.8.7.
For me, it was an issue with having the correct dependent gems, as well as the correct versions.
Here's how I got it working:
I ran:
sudo gem list
And compared the versions of specific gems with what I found here:
https://github.com/jnunemaker/twitter/blob/master/HISTORY.md (I simply searched for the word 'dependency' to see which versions twitter cared about.
I also found this diff:
https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3
And I compared the gems listed there with what I had installed, and I just made sure my system lined up with what I was seeing in the version notes. Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence.
I'm not sure why I still have to add
gem 'twitter', '1.7.1'
to my Gemfile, but alas, that's the last step required in order to get this stuff working.
Don't forget to restart your server, and you should be good!

Resources