「rails s」でwarning: already initialized constantが出る(再録)

この記事は2018年10月16日 に公開した記事の内容を少しだけ更新してます


最近さぼり気味なので久々の更新…. 「さぁやるぞ!」って時によくわからんトラブル起きるとやる気削がれるよな

ということで、rails sで開発サーバーを立てようとしたらすんごい大量のwarningが出てきた

/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:90: warning: already initialized constant FileUtils::VERSION
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:92: warning: previous definition of VERSION was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1188: warning: already initialized constant FileUtils::Entry_::S_IF_DOOR
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1267: warning: previous definition of S_IF_DOOR was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1446: warning: already initialized constant FileUtils::Entry_::DIRECTORY_TERM
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1541: warning: previous definition of DIRECTORY_TERM was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1448: warning: already initialized constant FileUtils::Entry_::SYSCASE
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1543: warning: previous definition of SYSCASE was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1501: warning: already initialized constant FileUtils::OPT_TABLE
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1596: warning: previous definition of OPT_TABLE was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1555: warning: already initialized constant FileUtils::LOW_METHODS
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1650: warning: previous definition of LOW_METHODS was here
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1562: warning: already initialized constant FileUtils::METHODS
/home/tesao/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.1.0/lib/fileutils.rb:1657: warning: previous definition of METHODS was here
=> Booting Puma
=> Rails 5.2.1 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3030
Use Ctrl-C to stop

環境

  • Ubuntu 18.04
  • Ruby 2.5.1
  • Ruby on Rails 5.2.1

原因?

gemでglobalインストールされたfileutilsが既に読み込まれてるのにrails側でも読み込もうとしてるっぽい

直った方法

ここのやり方で直った

要はgemをuninstallして、--defaultをつけてupdateしたらOK

$ 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
Done installing documentation for fileutils after 0 seconds
Done installing documentation for fileutils after 0 seconds
Gems updated: fileutils

$rails s
=> Booting Puma
=> Rails 5.2.1 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3030
Use Ctrl-C to stop

とりあえずやる気は完全に削がれなかったのでRailsがんばろー