带有Ruby 2.5.1控制台的Rails 5.2.0-`warning:`ʻaready`已初始化常量FileUtils :: VERSION [英] Rails 5.2.0 with Ruby 2.5.1 console - `warning:` `already` initialized constant FileUtils::VERSION

查看:126
本文介绍了带有Ruby 2.5.1控制台的Rails 5.2.0-`warning:`ʻaready`已初始化常量FileUtils :: VERSION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的新Rails应用程序目前遇到问题,更具体地说:

I'm currently experiencing an issue with my new rails application, more specifically:

  • Rails 5.2.0
  • Ruby 2.5.1p57(2018-03-29修订版63029)[x86_64-darwin17]
  • rvm 1.29.4(最新),作者:Michal Papis,Piotr Kuczynski,Wayne E. Seguin [ https://rvm.io]

当我运行rails c时,它会生成一个指向fileutils gem的警告链接,如下所示:

When I run rails c, it produces a warning links to fileutils gem as the following:

`/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:90:` `warning:` `already` initialized constant FileUtils::VERSION
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:92: warning: previous definition of VERSION was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1188: warning: already initialized constant FileUtils::Entry_::S_IF_DOOR
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1267: warning: previous definition of S_IF_DOOR was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1446: warning: already initialized constant FileUtils::Entry_::DIRECTORY_TERM
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1541: warning: previous definition of DIRECTORY_TERM was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1448: warning: already initialized constant FileUtils::Entry_::SYSCASE
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1543: warning: previous definition of SYSCASE was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1501: warning: already initialized constant FileUtils::OPT_TABLE
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1596: warning: previous definition of OPT_TABLE was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1555: warning: already initialized constant FileUtils::LOW_METHODS
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1650: warning: previous definition of LOW_METHODS was here
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/fileutils.rb:1562: warning: already initialized constant FileUtils::METHODS
/usr/local/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1657: warning: previous definition of METHODS was here

我遵循本指南http://railsapps.github.io/installrubyonrails-mac.html中概述的所有步骤.

I follow all the step as outlined in this guideline http://railsapps.github.io/installrubyonrails-mac.html.

您可以按照指南或执行以下步骤来复制问题:

You can replicate the issue by just following the guideline or with the following steps:

  1. rvm安装ruby-2.5.1
  2. 跟踪新应用
  3. cd应用
  4. 宝石更新
  5. 捆绑更新

观察并解决后,我发现Ruby 2.5.*随附的fileutils的默认版本为1.0.2,而gem update命令将安装另一个较新的版本1.1.0.因此,当我运行rails c时,将加载两个版本的fileutils.

After observing and working around, I've found that the default version of fileutils come with Ruby 2.5.* is 1.0.2 and the gem update command installs a another newer version 1.1.0. Therefore, there are two versions of fileutils are loaded when I run the rails c.

为解决此问题,我将--default选项附加到gem update命令.

To deal with this issue, I append --default option to the gem update command.

gem update --default

结果,我得到了两个默认版本,可以通过运行gem list | grep fileutils看到.这是我摆脱警告的唯一方法.

As a result, I got two default versions which can be seen by running gem list | grep fileutils. This is the only way I can get rid the warning.

mac: gem list | grep fileutils
fileutils (default: 1.1.0, default: 1.0.2)

我写这个问题的答案只是为了与可能遇到相同问题的人分享.由于无法在互联网上找到任何帮助,我花了几个小时对其进行整理.

I write this question with, kind of, answer just to share with someone who may experience the same issue. I spent hours to sort it out as I couldn't find any helps on the internet.

注意 :当我在macOS Sierra上使用rbenv而不是rvm时,会发生相同的问题.

Note: the same issue happens when I use rbenv instead of rvm on macOS Sierra.

请让我知道是否有人有更好的方法来处理此类问题.

Please let me know if anyone has a better approach to deal with such an issue.

干杯

推荐答案

我遇到了同样的问题.帖子中缺少的一个步骤是先卸载fileutils gem,然后使用默认选项更新gem.

I had the same issue. The one step missing from your post is to uninstall the fileutils gem first, then gem update with the default option.

gem uninstall fileutils
Successfully uninstalled fileutils-1.1.0
gem update --default
Updating installed gems
Updating fileutils
Fetching: fileutils-1.1.0.gem (100%)
Successfully installed fileutils-1.1.0

这为我摆脱了冗长的fileutils消息.

That got rid of the verbose fileutils messages for me.

更新:执行 gem update fileutils --default ,而不是gem update --default.这个过程也应该适用于其他宝石.感谢Matijs van Zuijlen的帮助.

Update: Instead of gem update --default, do gem update fileutils --default. This process should work for other gems too. Thanks to Matijs van Zuijlen for this.

这篇关于带有Ruby 2.5.1控制台的Rails 5.2.0-`warning:`ʻaready`已初始化常量FileUtils :: VERSION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆