How to run a specific version of a ruby gem - ruby-on-rails

I am running brakeman outside of my Gemfile, so am not using bundler.
If I do gem list, I can see I have the following for brakeman
brakeman (3.3.3, 3.3.2, 3.1.4, 3.1.2)
But if I do brakeman --version, I get
brakeman 3.1.2
so I am not using the latest version. If I do gem update brakeman or
gem update brakeman, '3.3.3,
I get
Updating installed gems
Nothing to update
So how do I run brakeman version 3.3.3?

If you have several gem versions installed and you want to invoke a specific version from the command-line, you could use:
brakeman _3.3.3_ [args go here]
This is not specific to brakeman, you can do this for most other gems as well.

I can't reproduce this issue, but I can think of a few reasons why this might happen:
Bundler artifacts (perhaps in .bundle/) pointing to the old version. Try running in a different directory and see if it still happens
A bug in RubyGems (try gem update --system)
During install, it asked if you wanted to replace the brakeman binary and you selected "no"
If you are using a Ruby version manager, maybe one version is on a different path than another (like a system gem versus one managed by rvm)
Any number of GEM_PATH, bundler, gem, rvm weirdness that sometimes occurs
In any case, if I were you I'd gem uninstall brakeman, remove all versions, and install fresh. If you are using rvm, start with a fresh gemset or rvm gemset empty the current one.

I had a similar problem: I uninstalled a certain gem version, but the version still showed up.
TL;DR: rbenv rehash did the trick. (Only valid for rbenv users, obviously)

Related

In a Ruby on Rails installation, what is causing webrick to be outdated and why `gem i webrick` can update it?

I have a new Mac computer and installed rails on it, and then I tried out the command
gem outdated
for some reason, it showed one of the gems outdated:
webrick (1.4.2 < 1.6.0)
I wonder why it is outdated on the first installed, and when I did
sudo gem install webrick
it actually installed 1.6.0 onto the system. Doesn't it require gem update instead of install to update something? How come install also updated it?
Not exactly, gem install GEM_NAME will install the last version available if you don't specify a version when installing, and you can have more than 1 version of the same gem on your machine.
you can run gem environment, and check where gems are installed, go to that folder and you will see both version gems folder there.
so when you create a rails project for example and add a specific version of a gem in the gemfile and another version on another project, you can have both without problems

omniauth requires Ruby version >= 2.1.9. issue while installing gem file

Got an error after typing "bundle install" with some sort of issue with the Ruby version. Have been installed many-many gems so far and never got incompabilities with the Ruby version.
What's the best way to upgrade the Ruby version to get back on track with the "bundle install" without putting the app at "risk"?
Here it is what I have done:
1st - Added the twitter omniauth gem to my gemfile.
2nd - Created a omniauth.rb file in the app/config/initializers folder.
3rd - Typed the "bundle install" command and got the following error: "omniauth requires Ruby version >= 2.1.9."
Dependencies can specify a required_ruby_version in their .gemspec file. In this case, one of your sub-dependencies (omniauth - a sub-dependency of omniauth-oauth, which is in turn a sub-dependency of omniauth-twitter) has had such a requirement since v1.5.0.
To get a working install, you've got two options:
Pin to an older version of omniauth, by adding gem "omniauth", "~> 1.4.2" to your Gemfile. This will ensure Bundler uses an older version of omniauth. However, that may cause conflicts with other gems, leaving you with the same problem - indeed, it's probably the reason Bundler didn't automatically try to install an older version.
Update your Ruby version. If you have a .ruby-version file in your application, update the version there to 2.1.9. Similarly if your Gemfile has a ruby "..." line in it, update that too. You'll probably also need to install the new version of Ruby locally - with rbenv you can use $ rbenv install 2.1.9, or if you use RVM try $rvm install 2.1.9.
My recommendation would be option 2 (updating your Ruby version).

How do I delete gems for old ruby versions installed by bundler?

I want to free up disk space in my production environment taken up by gems installed for old ruby versions. I don't believe bundle clean will work in this instance, because I don't think it cleans out the old gems for other rubies.
These gems are installed via capistrano and are installed in a custom location, rather than system wide. In my /path/to/my-project/shared/bundle/ruby dir, I see 2 subdirs - 2.2.0 & 2.3.0. Since I am now using ruby 2.3, is it safe just to delete the 2.2.0 directory? Is there anything else I need to do?
Use "sudo gem cleanup" to remove all previously installed gems which respecting all the dependencies be it on old version of ruby. You can see all the gems that ll be removed with command "sudo gem cleanup -d"
here is how you can remove a specific version of the gem:
gem uninstall (gem name here) --version (version number here)
Go to Gemfile.lock and delete all its content. Then you go to Gemfile and delete gems you do not want anymore. After, You type bundle install and it will install just the ones you want.

Do I have to install Ruby from source to get Ruby 2.2.0 and Rails 4.2.0 installed on my windows machine?

I currently have Ruby 2.2.6 and Rails 5.0.1 installed on my Windows 10 machine. I have cloned an existing project that has the following settings included in its Gemfile:
# Lock-in Lang and Framework:
ruby '2.2.0'
gem 'rails', '4.2.0'
I'm having a surprisingly hard time figuring out how to get Ruby 2.2.0 and Rails 4.2.0 installed. Ruby has good documentation of different installation options, but I think I've exhausted the Windows options without any success. Here are a couple I tried:
Installers: I couldn't find an option for downloading either from RailsInstaller, RubyInstaller, and Bitnami.
RVM: I tried (unsuccessfully) following this blog post to install cygwin so that I could use RVM, but then saw in the comments that the author now recommends spinning up a linux VM rather that using this method.
Pik and Uru: It appears Pik is no longer maintained, and I couldn't figure how to download new versions and ruby and rails with Uru as opposed to managing already downloaded versions.
EDIT: I also tried simply changing the version numbers for ruby and rails in the Gemfile to 2.2.6 and 5.0.1. When I do this I (very understandably) get a message when I try to use a rails command saying I need to run bundle update rails. When I run that rails update I get the following error: Bundler could not find compatible versions for gem "rack". I've done some googling on that option, and it looks like resolving that issue might be possible but requires some more involved tinkering with my Gemfile configuration.
I think my next option is to install Ruby from the source, but I wanted to throw a question up here first to make sure I'm not missing an easier method. So my question is - is it really this hard to get an older minor release of ruby and rails installed on Windows? I realize that the majority of users are probably looking for the most recent release, but it doesn't seem to me that my use case is terribly unique.
The oldest available Ruby 2.2.x via RubyInstaller is 2.2.1
So, the answer to your question is, "Yes, you'll have to build from source."
But then again,
v2.x of gem "rack" requires at least Ruby v2.2.2
And depending on what other gems are included in your Gemfile, you'll still have to reconfigure your Gemfile to get this app running.
So the best solution is probably to use the latest patch version of Ruby 2.2.x and lock rails to 4.2.x. (The app may not be compatible with Rails 5.x)
# Lock-in Lang and Framework:
ruby '2.2.6'
gem 'rails', '~> 4.2'
Then run bundle install to install all the gems required by the Gemfile

How to stop rails from adding BUNDLED WITH to the Gemfile.lock

I'm working with a distributed team of developers and I'm getting this issue of having to commit the Gemfile.lock with bundled with info added to the bottom:
BUNDLED WITH
1.10.2
We're obviously using different versions of things, ie rvm/rbenv, and I'm wondering if there's a way to stop my system doing this.
Bundler version 1.10.2 (obviously)
After digging around a bit, and looking through those issues and comments shared by Jorge, you really only have two options:
Downgrade your version of bundler to something earlier than 1.10
Ask your whole team to update their versions of bundler to something later than 1.10
gem uninstall bundler
gem install bundler -v 1.9.9
But as long as the downgrade doesn't cause any issues, it should be fine.
The developers for the bundler gem are not going to make any changes to the gem that will eliminate this problem. They're reasoning is that eventually everyone will be upgraded to something after 1.10.
Locate the file lib/bundler/definition.rb in your local installation of the bundler gem (you can use gem env to locate the folder where your gems are installed) and remove these three lines
# Record the version of Bundler that was used to create the lockfile
out << "\nBUNDLED WITH\n"
out << " #{lock_version}\n"
You might need to restart spring after the change

Resources