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

后端 未结 15 1082
生来不讨喜
生来不讨喜 2020-12-13 11:32

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?

相关标签:
15条回答
  • 2020-12-13 12:05

    In newer version, used bundle show gem_name

    [DEPRECATED] use `bundle info gem_name` instead of `bundle show gem_name`
    
    0 讨论(0)
  • 2020-12-13 12:14

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

    bundle info [gemname]
    
    0 讨论(0)
  • 2020-12-13 12:16

    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
    
    0 讨论(0)
  • 2020-12-13 12:16

    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.

    0 讨论(0)
  • 2020-12-13 12:17

    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.

    0 讨论(0)
  • 2020-12-13 12:22
    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)
    
    0 讨论(0)
提交回复
热议问题