Rails 5.2.0 with Ruby 2.5.1 console - `warning:` `already` initialized constant FileUtils::VERSION
Asked Answered
H

3

62

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

  • Rails 5.2.0
  • Ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
  • rvm 1.29.4 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

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

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 install ruby-2.5.1
  2. rails new app
  3. cd app
  4. gem update
  5. bundle update

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.

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

gem update --default

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.

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.

Cheers,

Hershey answered 14/7, 2018 at 2:27 Comment(0)
L
109

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 fileutils --default
Updating installed gems
Updating fileutils
Fetching: fileutils-1.1.0.gem (100%)
Successfully installed fileutils-1.1.0

That got rid of the verbose fileutils messages for me.

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.

Leftward answered 9/8, 2018 at 15:3 Comment(12)
That did it for me too. Thanks!Grillo
Worked! Care to explain why?Uriah
a wild guess is that there are multiple gem paths that is setup in your local machine. you can check via gem env. fileutil might be loaded from multiple sources at one point and can be sorted after resetup?Facetious
Oh my god. Thank you so much. Every cell of my body feels better now that I don't have those messages.Valente
On second thought: Sometimes I get ` gem "fileutils" cannot be uninstalled because it is a default gem`. How do I proceed when this happens?Valente
Amazing. So simple, how come many so called' code artisans' discussed this for years while a single demigod had the answer?Cyndi
Running gem update --default is not such a good idea since it turns all updated gems into default gems. Instead, do gem update fileutils --default.Stettin
veasna, @Dan_McCallum, and Matijs_van_Zuijlen, advice that saved me from an insane asylum in 2019 :DKutzenco
This works for all other gems too, I had multiple giving these errors and doing this one by one removed all of them.Liebermann
# gem uninstall fileutils ERROR: While executing gem ... (Gem::InstallError) gem "fileutils" cannot be uninstalled because it is a default gemDecibel
extremely useful and perfect solution I have used the updated instructionBax
Maybe you should update the code too to use gem update fileutils --default instead of gem update --default?Kurth
N
46

It works for me:

bundle clean --force

bundle clean(1)
Clean up unused gems in your Bundler directory

Napkin answered 23/12, 2019 at 3:24 Comment(3)
Thank you! Best answer to me!Monteverdi
@Monteverdi me too. This is simple and it works.Braunstein
the gem update didnt work for me, the clean fixed all warningsKey
C
0

Since neither of these solutions have been officially selected as the correct answer, I'll drop my solution for a "similar, but not exactly the same" error.

I had a handful of "warning already initialized constant XXX::..." because of the faraday gem.

I had to add additional gems to my Gemfile, per this article

Once I added the gem that faraday was depending on and bundle installed, these warnings were cleared.

For your warnings, it appears the FileUtils gem needs to be added to your gemfile because it's the Gem thats referenced in the warning

Cressler answered 27/12, 2022 at 1:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.