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

后端 未结 15 1084
生来不讨喜
生来不讨喜 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:23

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

    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.

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

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

    bundle show [gemname]
    
    0 讨论(0)
  • 2020-12-13 12:29
    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
    
    0 讨论(0)
  • 2020-12-13 12:29

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

    bundle show devise
    

    and it will printout the current gem version.

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

    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

    0 讨论(0)
提交回复
热议问题