Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check gem version number

My setup: Rails 3.0.9, Ruby 1.9.2

I want to check the gem version for my app through the Rails console. In my gemfile, I have

gem 'rack', '1.2.3'

Ran bundle install after. In the Rails console,

>> Rack.version
=> "1.1"

Any idea why?

UPDATE

Gemfile.lock

GEM
  remote: http://rubygems.org/
  specs:
    actionpack (3.0.9)
      ...
      rack (~> 1.2.1)
      ...

    rack (1.2.3)

    rack-mount (0.6.14)
      rack (>= 1.0.0)

    warden (1.0.4)
      rack (>= 1.0)

DEPENDENCIES
...  
rack (= 1.2.3)
...

There are several rack versions listed in gemfile.lock.

like image 297
Bob Avatar asked Aug 04 '11 20:08

Bob


People also ask

How do I check my bundle version?

To view this information: Open the App bundle explorer page (Release > App bundle explorer). Select the version filter near the top right of the page. On the “Choose a version” table, select the right arrow on the version that you want to view.

How do I check if a ruby gem is installed?

To check if a specific version is installed, just add --version , e.g.: gem list -i compass --version 0.12.

What is gem command?

The gem command allows you to interact with RubyGems. Ruby 1.9 and newer ships with RubyGems built-in but you may need to upgrade for bug fixes or new features. To upgrade RubyGems, visit the download page. If you want to see how to require files from a gem, skip ahead to What is a gem. Finding Gems.


2 Answers

Rack.version

will return the protocol version,

Rack.release

is probably what you are you looking for.

https://github.com/rack/rack/blob/master/lib/rack.rb#L14

Otherwise:

Gem.loaded_specs["rack"]

Example:

Gem.loaded_specs["rack"]
# => #<Gem::Specification name=rack version=1.3.2> 
Gem.loaded_specs["rack"].version
# => #<Gem::Version "1.3.2"> 
Gem.loaded_specs["rack"].version.to_s
# => "1.3.2"
like image 128
kain Avatar answered Oct 14 '22 22:10

kain


Every gem has ::VERSION constant.. so just use Rack::VERSION or OpenSSL::VERSION in console which should give you the version of gem loaded in that console.

like image 36
Salman Siddiqui Avatar answered Oct 14 '22 22:10

Salman Siddiqui