简体   繁体   English

检查 gem 版本号

[英]Check gem version number

My setup: Rails 3.0.9, Ruby 1.9.2我的设置:Rails 3.0.9,Ruby 1.9.2

I want to check the gem version for my app through the Rails console.我想通过 Rails 控制台检查我的应用程序的 gem 版本。 In my gemfile, I have在我的 gemfile 中,我有

gem 'rack', '1.2.3'

Ran bundle install after.运行捆绑安装后。 In the Rails console,在 Rails 控制台中,

>> 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 . gemfile.lock列出了几个机架版本。

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 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"

每个 gem 都有 ::VERSION 常量..所以只需在控制台中使用 Rack::VERSION 或 OpenSSL::VERSION 这应该会给你在该控制台中加载的 gem 版本。

Maybe you have multiple version of rack installed, try running gem uninstall rack and see if it offers you two options to choose from, Rack 1.1 and Rack 1.2.3.也许你安装了多个版本的 rack,尝试运行gem uninstall rack看看它是否提供了两个选项供你选择,Rack 1.1 和 Rack 1.2.3。 If so, choose to uninstall Rack 1.1.如果是这样,请选择卸载 Rack 1.1。

If this still does not work, just uninstall Rack and try running bundle update.如果这仍然不起作用,只需卸载 Rack 并尝试运行 bundle update。

I had this problem when I was using multiple rake versions 0.8.7 and 0.9.2, this helped me.我在使用多个 rake 版本 0.8.7 和 0.9.2 时遇到了这个问题,这对我有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM