rakeがwarning: already initialized constantで起動しない

rakeコマンドを動かそうとしたら、動きません。

# 症状

```
$ rake -T
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_utils.rb:10: warning: already initialized constant FileUtils::RUBY
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_utils.rb:10: warning: previous definition of RUBY was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_utils.rb:109: warning: already initialized constant FileUtils::LN_SUPPORTED
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_utils.rb:109: warning: previous definition of LN_SUPPORTED was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_utils_ext.rb:17: warning: already initialized constant Rake::FileUtilsExt::DEFAULT
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_utils_ext.rb:17: warning: previous definition of DEFAULT was here
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:44: warning: already initialized constant Rake::FileList::ARRAY_METHODS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:44: warning: previous definition of ARRAY_METHODS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:47: warning: already initialized constant Rake::FileList::MUST_DEFINE
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:47: warning: previous definition of MUST_DEFINE was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:51: warning: already initialized constant Rake::FileList::MUST_NOT_DEFINE
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:51: warning: previous definition of MUST_NOT_DEFINE was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:55: warning: already initialized constant Rake::FileList::SPECIAL_RETURN
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:55: warning: previous definition of SPECIAL_RETURN was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:61: warning: already initialized constant Rake::FileList::DELEGATING_METHODS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:61: warning: previous definition of DELEGATING_METHODS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:86: warning: already initialized constant Rake::FileList::GLOB_PATTERN
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:86: warning: previous definition of GLOB_PATTERN was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:381: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PATTERNS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:381: warning: previous definition of DEFAULT_IGNORE_PATTERNS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:387: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PROCS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/file_list.rb:387: warning: previous definition of DEFAULT_IGNORE_PROCS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:3: warning: already initialized constant Rake::VERSION
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:3: warning: previous definition of VERSION was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MAJOR
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: previous definition of MAJOR was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MINOR
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: previous definition of MINOR was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::BUILD
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: previous definition of BUILD was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::OTHER
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:6: warning: previous definition of OTHER was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:8: warning: already initialized constant Rake::Version::NUMBERS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/version.rb:8: warning: previous definition of NUMBERS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/linked_list.rb:110: warning: already initialized constant Rake::LinkedList::EMPTY
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/linked_list.rb:110: warning: previous definition of EMPTY was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/scope.rb:41: warning: already initialized constant Rake::Scope::EMPTY
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/scope.rb:41: warning: previous definition of EMPTY was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/promise.rb:12: warning: already initialized constant Rake::Promise::NOT_SET
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/promise.rb:12: warning: previous definition of NOT_SET was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:13: warning: already initialized constant Rake::CommandLineOptionError
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:13: warning: previous definition of CommandLineOptionError was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:41: warning: already initialized constant Rake::Application::DEFAULT_RAKEFILES
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:41: warning: previous definition of DEFAULT_RAKEFILES was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/task_arguments.rb:108: warning: already initialized constant Rake::EMPTY_TASK_ARGS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/task_arguments.rb:108: warning: previous definition of EMPTY_TASK_ARGS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/invocation_chain.rb:55: warning: already initialized constant Rake::InvocationChain::EMPTY
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/invocation_chain.rb:55: warning: previous definition of EMPTY was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/early_time.rb:21: warning: already initialized constant Rake::EARLY
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/early_time.rb:21: warning: previous definition of EARLY was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/late_time.rb:17: warning: already initialized constant Rake::LATE
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/late_time.rb:17: warning: previous definition of LATE was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:4: warning: already initialized constant Rake::Backtrace::SYS_KEYS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:4: warning: previous definition of SYS_KEYS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:5: warning: already initialized constant Rake::Backtrace::SYS_PATHS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:5: warning: previous definition of SYS_PATHS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:8: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:8: warning: previous definition of SUPPRESSED_PATHS was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:12: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS_RE
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:12: warning: previous definition of SUPPRESSED_PATHS_RE was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:16: warning: already initialized constant Rake::Backtrace::SUPPRESS_PATTERN
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/backtrace.rb:16: warning: previous definition of SUPPRESS_PATTERN was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake.rb:70: warning: already initialized constant FileList
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake.rb:70: warning: previous definition of FileList was here
/home/natales/Desktop/rails-proj/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/lib/rake.rb:71: warning: already initialized constant RakeFileUtils
/home/natales/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake.rb:71: warning: previous definition of RakeFileUtils was here
```

# 原因
ruby側に入ってるgemとRailsプロジェクトに入ってるgemが重複ロードが原因です。

# 解決

今回はRailsプロジェクトに入ってるgemを優先したかったので、ruby側に入ってるgemを削除します。
**注意：標準でインストールされているgem以外は消えます。**

```shell-session
$ gem uninstall -I -a -x --user-install --force
```

消したgemを確認すると、

```shell-session
 $ gem list
*** LOCAL GEMS ***

bigdecimal (default: 1.3.4)
cmath (default: 1.0.0)
csv (default: 1.0.0)
date (default: 1.0.0)
etc (default: 1.0.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.0.2)
io-console (default: 0.4.6)
ipaddr (default: 1.2.0)
json (default: 2.1.0)
openssl (default: 2.1.0)
psych (default: 3.0.2)
rdoc (default: 6.0.1)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
stringio (default: 0.0.1)
strscan (default: 1.0.0)
webrick (default: 1.4.2)
zlib (default: 1.0.0)
```

入ってたのは根こそぎ消えてますね。

bundlerも消えてるので入れます。

```shell-session
 $ gem install bundler
```

rakeを確認します。

```shell-session
 $ bundle e rake -T
rake about                              # List versions of all Rails framew...
rake active_storage:install             # Copy over the migration needed to...
rake app:template                       # Applies the template supplied by ...
```

うまくいってますね。

# 参考
[rakeとかでwarning: already initialized constant Rake::VERSIONみたいなエラーが出た](http://daily.belltail.jp/?p=2429)
[gem をクリーンにする。](https://qiita.com/katoy/items/9bcba54b88c5fc7d9aa6)