Ruby-on-rails 如何判断 Rails 应用程序使用的是哪个版本的 gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1621405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:53:12  来源:igfitidea点击:

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

ruby-on-railsrubygems

提问by Steve Brewer

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?

我正在调查一个 rails 应用程序 - prod 服务器安装了特定 gem 的两个版本,我怎么知道 prod 应用程序正在使用哪个版本?

回答by BJ Clark

In Rails 3 and Rails 4, use bundle show

在 Rails 3 和 Rails 4 中,使用 bundle show

In Rails 2, rake gemswill print out what gems, dependencies, and versions are installed, frozen, etc.

在 Rails 2 中,rake gems将打印出安装、冻结等的 gem、依赖项和版本。

回答by Stina

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

如果您使用捆绑程序,那么您可以从

bundle show [gemname]

回答by SnapShot

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:

我花了比预期更长的时间来查找和整理这些信息,所以我想把它张贴在一个地方供其他人查看。我还想为 Rails 3 澄清一下:

  • script/about has been replaced with rake aboutThe details are here. If you are interested a list of all the command line changes for Rails 3 they can be found here.

  • rake gemsdoes not work in Rails 3. Instead you should use bundle show

  • script/about 已替换为rake about详细信息在这里。如果您对 Rails 3 的所有命令行更改的列表感兴趣,可以在此处找到它们。

  • rake gems在 Rails 3 中不起作用。相反,您应该使用 bundle show

As an example, you can save all versions of your gems to a file for viewing with:

例如,您可以将所有版本的 gem 保存到一个文件中以供查看:

gem list > all_gems.txt

gem list > all_gems.txt

and you can see what versions your Rails app is using with:

并且您可以查看您的 Rails 应用程序使用的版本:

bundle show > project_gems.txt

bundle show > project_gems.txt

Using an editor like Vim you can easily use vimdiff to see the changes

使用 Vim 之类的编辑器,您可以轻松地使用 vimdiff 查看更改

回答by gtd

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

回答by Xing L

In the terminal

在终端

bundle show [gem-name]
bundle show | grep [gem-name]

or

或者

gem list | grep [gem-name]

[gem-name] should be replaced as gem name you are going to look for.

[gem-name] 应该替换为您要查找的 gem 名称。

回答by SooDesuNe

There's also a list in Gemfile.lock, located in the root directory of your app.

中还有一个列表Gemfile.lock,位于应用程序的根目录中。

For this reason I leave Gemfile.lockout 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.

出于这个原因,我离开Gemfile.lock了我的.gitignore. 当我忘记在GemFile.

回答by Waseem

Try using script/about. Your config/environment.rbalso has information about it.

尝试使用script/about. 你config/environment.rb也有关于它的信息。

In your config/environment.rbyou can specify which version of a particular gemthe application should use. However if you have multiple versions of a geminstalled on your machine and you do not specify the version, the latest version of that gem will be used by the application.

在你config/environment.rb可以指定一个特定版本gem的应用程序应该使用。但是,如果您gem的机器上安装了多个版本的 a并且您没有指定版本,则应用程序将使用该 gem 的最新版本。

回答by ImranNaqvi

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)

回答by John Hyland

script/aboutwill 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:

script/about会告诉您正在使用的核心 Rails 和 Rack gem 的版本,但不会告诉您其他任何版本。理想情况下,如果您查看config/environment.rb,应该有一个如下所示的部分:

# 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.

幸运的话,该应用程序的作者将在其中包含所有必需的 gem 和版本。然而,版本在这个文件中是可选的,最终没有什么能阻止没有经验的开发人员require 'rubygems'; require 'some_random_thing'在任何给定文件的顶部打一个。

If you see that a gem is being required, but no version is specified, you can type gem listto see all the versions of all the gems on the system. By default, it will be using the latest one available.

如果您看到需要 gem,但未指定版本,则可以键入gem list以查看系统上所有 gem 的所有版本。默认情况下,它将使用可用的最新版本。

回答by Bilal A.Awan

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

bundle show gemname Ie for devise 你必须这样写

bundle show devise

and it will printout the current gem version.

它会打印出当前的 gem 版本。