Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.


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

bundle show [gemname]

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


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

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

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.


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.