How to tell which version of a gem a rails app is using
Asked Answered
P

16

136

I'm investigating a rails app - the prod server has two version of a specific gem installed, how can I tell which version the prod app is using?

Patterman answered 25/10, 2009 at 17:0 Comment(3)
Are you asking which version of rails, or which version of some other gem?Ninette
Which version of a particular gem.Patterman
I have a gem frozen under vendors/gems, and then have a newer version of the gem installed in the default gems location. I'm looking from something from rails that says "I loaded this gem from this location".Patterman
N
192

In Rails 3 and Rails 4, use bundle show

In Rails 2, rake gems will print out what gems, dependencies, and versions are installed, frozen, etc.

Ninette answered 26/10, 2009 at 4:28 Comment(4)
This will only work if the gem as been specified in the environment.rb file. If the developer just required it somewhere, rake gems won't work.August
(Or in one of the config/environments/* files, depending on your RAILS_ENV.)August
If you want to filter the list do bundle show | grep gem_name, example for compass: bundle show | grep compassDeadhead
So what does it mean when you type bundle show and you get a bunch of Gems with versions including "rails 2.3.17) and you type rake gems and you get what looks like a legend (I=Installed, etc) but no gems/versions? Do I have rails version 2 or not? Maybe I have rails version 2 and a more advanced bundler? Is this good/bad? (Yes, I know it's bad to have such an old version of rails, I want to know if it's catastrophic to have such a mismatched (if it is) rails and bundler).Generality
M
49

If you use bundler, then you can get the version from

bundle show [gemname]
Makeup answered 18/11, 2011 at 20:39 Comment(2)
I came to this question because I am trying to move to bundler (probably many people also, because Heroku now requires this)Consignment
This is deprecated. Use bundle info [gemname] instead.Flaw
B
39

It took me longer than expected to find and sort through this information so I wanted to post it here in one place for others to view. I also wanted to clarify this a bit for Rails 3:

  • script/about has been replaced with rake about The details are here. If you are interested a list of all the command line changes for Rails 3 they can be found here.

  • rake gems does not work in Rails 3. Instead you should use bundle show

As an example, you can save all versions of your gems to a file for viewing with:

gem list > all_gems.txt

and you can see what versions your Rails app is using with:

bundle show > project_gems.txt

Using an editor like Vim you can easily use vimdiff to see the changes

Bedstead answered 29/11, 2011 at 15:19 Comment(0)
B
8

In the terminal

  bundle show <gem-name>
  bundle show | grep <gem-name>

or

  gem list | grep <gem-name>

For example:

  bundle show rails
  bundle show | grep rails

  gem list | grep rails
Brumbaugh answered 26/1, 2015 at 20:57 Comment(0)
H
6

There probably is a more direct way to find this out, but if you load up a console and require a specific version like so:

gem 'RedCloth', '3.0.4'

It will tell you what version is already activated:

=> Gem::LoadError: can't activate RedCloth (= 3.0.4, runtime) for [], already activated RedCloth-4.2.2
Hauck answered 25/10, 2009 at 17:42 Comment(0)
R
5

There's also a list in Gemfile.lock, located in the root directory of your app.

For this reason I leave Gemfile.lock out of my .gitignore. This has saved me more than once when I forgot to specify the gem version in GemFile, and a gem got updated with breaking changes.

Rameses answered 18/12, 2012 at 20:56 Comment(0)
A
4

Try using script/about. Your config/environment.rb also has information about it.

In your config/environment.rb you can specify which version of a particular gem the application should use. However if you have multiple versions of a gem installed on your machine and you do not specify the version, the latest version of that gem will be used by the application.

Adenoid answered 25/10, 2009 at 17:13 Comment(0)
W
4
gem list <gemname>

It will show all the matching gems e.g if some one do

gem list rack

Then th output will be as following

*** LOCAL GEMS ***

rack (1.6.4)
rack-mount (0.6.14)
rack-test (0.6.3, 0.6.2, 0.5.7)
Wally answered 7/10, 2015 at 7:54 Comment(0)
A
2

script/about will tell you what versions of the core Rails and Rack gems you're using, but not anything else. Ideally, if you look in config/environment.rb, there should be a section that looks like this:

# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"

With any luck, the author of the app will have included any required gems and versions there. However, the versions are optional in this file, and ultimately nothing stops an inexperienced developer from just slapping a require 'rubygems'; require 'some_random_thing' at the top of any given file.

If you see that a gem is being required, but no version is specified, you can type gem list to see all the versions of all the gems on the system. By default, it will be using the latest one available.

August answered 25/10, 2009 at 21:39 Comment(2)
Does your script/about tell you about gems? Mine just tells me what version of ruby, rails and environment I'm using.Ninette
Right, Rails (and Rack) are both gems, and script/about will tell you what versions of them are running, along with the core Rails stuff (ActiveSupport, etc) but it won't tell you about any other gems. Sorry if that wasn't clear.August
H
2
bundle exec gem which gem_name

Is probably what you can use:

$› bundle exec gem which rails
/Users/xxxx/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.7/lib/rails.rb
Heck answered 24/11, 2014 at 10:55 Comment(1)
I was looking for information about which version of a globally-installed gem was being executed in an arbitrary folder and this led me to what I believe is the correct solution - gem which gem_nameKosciusko
F
2

If you use bundler, then you can get the version using:

bundle info [gemname]
Flaw answered 12/5, 2020 at 23:29 Comment(0)
K
1

bundle show gemname I.e for devise you have to write like

bundle show devise

and it will printout the current gem version.

Klara answered 30/1, 2019 at 12:12 Comment(0)
G
1

In newer version, used bundle show gem_name

[DEPRECATED] use `bundle info gem_name` instead of `bundle show gem_name`
Grannias answered 12/2, 2020 at 3:52 Comment(0)
E
0

try this one for local gem :

gem list gemname | grep -P '(^|\s)\Kgemname(?=\s|$)'

If you use bundle:

bundle exec gem list gemname | grep -P '(^|\s)\Kgemname(?=\s|$)'
Earp answered 16/12, 2016 at 12:17 Comment(0)
S
0

bundle info <your-gem> --version will print out the installed version string

Sonatina answered 29/4 at 23:11 Comment(0)
H
-8

In Gemfile , there should be the answer:

gem 'rails', '4.0.0.rc1'
Haile answered 17/5, 2013 at 11:5 Comment(1)
Gemfile won't always explicitly declare a version number.Viewing

© 2022 - 2024 — McMap. All rights reserved.