Ruby
Rails

rakeコマンドを発動するとalready initialized constant FileUtils::RUBYと怒られる

エラー内容

railsアプリを作っていたらこんなエラーに遭遇。

MacBook-Pro:crawlerapp User$ rake -T
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: already initialized constant FileUtils::RUBY
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: previous definition of RUBY was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: already initialized constant FileUtils::LN_SUPPORTED
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: previous definition of LN_SUPPORTED was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_utils_ext.rb:17: warning: already initialized constant Rake::FileUtilsExt::DEFAULT
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/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
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:44: warning: already initialized constant Rake::FileList::ARRAY_METHODS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:44: warning: previous definition of ARRAY_METHODS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:47: warning: already initialized constant Rake::FileList::MUST_DEFINE
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:47: warning: previous definition of MUST_DEFINE was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:51: warning: already initialized constant Rake::FileList::MUST_NOT_DEFINE
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:51: warning: previous definition of MUST_NOT_DEFINE was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:55: warning: already initialized constant Rake::FileList::SPECIAL_RETURN
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:55: warning: previous definition of SPECIAL_RETURN was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:61: warning: already initialized constant Rake::FileList::DELEGATING_METHODS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:61: warning: previous definition of DELEGATING_METHODS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:86: warning: already initialized constant Rake::FileList::GLOB_PATTERN
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:86: warning: previous definition of GLOB_PATTERN was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:381: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PATTERNS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:381: warning: previous definition of DEFAULT_IGNORE_PATTERNS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:387: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PROCS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:387: warning: previous definition of DEFAULT_IGNORE_PROCS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:3: warning: already initialized constant Rake::VERSION
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:3: warning: previous definition of VERSION was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MAJOR
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of MAJOR was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MINOR
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of MINOR was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::BUILD
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of BUILD was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::OTHER
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of OTHER was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:8: warning: already initialized constant Rake::Version::NUMBERS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:8: warning: previous definition of NUMBERS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/linked_list.rb:110: warning: already initialized constant Rake::LinkedList::EMPTY
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/linked_list.rb:110: warning: previous definition of EMPTY was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/scope.rb:41: warning: already initialized constant Rake::Scope::EMPTY
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/scope.rb:41: warning: previous definition of EMPTY was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/promise.rb:12: warning: already initialized constant Rake::Promise::NOT_SET
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/promise.rb:12: warning: previous definition of NOT_SET was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:13: warning: already initialized constant Rake::CommandLineOptionError
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:13: warning: previous definition of CommandLineOptionError was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:41: warning: already initialized constant Rake::Application::DEFAULT_RAKEFILES
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:41: warning: previous definition of DEFAULT_RAKEFILES was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/task_arguments.rb:108: warning: already initialized constant Rake::EMPTY_TASK_ARGS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/task_arguments.rb:108: warning: previous definition of EMPTY_TASK_ARGS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/invocation_chain.rb:55: warning: already initialized constant Rake::InvocationChain::EMPTY
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/invocation_chain.rb:55: warning: previous definition of EMPTY was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/early_time.rb:21: warning: already initialized constant Rake::EARLY
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/early_time.rb:21: warning: previous definition of EARLY was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/late_time.rb:17: warning: already initialized constant Rake::LATE
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/late_time.rb:17: warning: previous definition of LATE was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:4: warning: already initialized constant Rake::Backtrace::SYS_KEYS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:4: warning: previous definition of SYS_KEYS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:5: warning: already initialized constant Rake::Backtrace::SYS_PATHS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:5: warning: previous definition of SYS_PATHS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:8: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:8: warning: previous definition of SUPPRESSED_PATHS was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:12: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS_RE
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:12: warning: previous definition of SUPPRESSED_PATHS_RE was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:16: warning: already initialized constant Rake::Backtrace::SUPPRESS_PATTERN
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:16: warning: previous definition of SUPPRESS_PATTERN was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake.rb:70: warning: already initialized constant FileList
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:70: warning: previous definition of FileList was here
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/rake-12.3.0/lib/rake.rb:71: warning: already initialized constant RakeFileUtils
/Users/User/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:71: warning: previous definition of RakeFileUtils was here
Downloading https://www.booking.com/hotel/us/hi-san-francisco-downtown.html?/AppsApi/GetIndexData?indexOrBond=bond&ClientCode=WSJ
rake aborted!
Cliver::Dependency::NotFound: Could not find an executable ["phantomjs"] on your path.
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:143:in `raise_not_found!'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/cliver-0.3.2/lib/cliver/dependency.rb:116:in `detect!'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/cliver-0.3.2/lib/cliver.rb:24:in `detect!'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/client.rb:51:in `initialize'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/client.rb:14:in `new'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/client.rb:14:in `start'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/driver.rb:44:in `client'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/driver.rb:25:in `browser'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/poltergeist-1.16.0/lib/capybara/poltergeist/driver.rb:97:in `visit'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/capybara-2.16.1/lib/capybara/session.rb:276:in `visit'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/capybara-2.16.1/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
/Users/User/Projects/github/crawlerapp/crawlerapp/lib/tasks/scrape.rake:18:in `get_bookingcom_page'
/Users/User/Projects/github/crawlerapp/crawlerapp/lib/tasks/scrape.rake:46:in `<top (required)>'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:648:in `load'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:648:in `block in run_tasks_blocks'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:648:in `each'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:648:in `run_tasks_blocks'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/application.rb:440:in `run_tasks_blocks'
/Users/User/Projects/github/crawlerapp/crawlerapp/vendor/bundle/ruby/2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:457:in `load_tasks'
/Users/User/Projects/github/crawlerapp/crawlerapp/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)

原因

rakeとかでwarning: already initialized constant Rake::VERSIONみたいなエラーが出たが非常に参考になった。

原因は、rails newしたあと一回普通にbundle installしたのですが、その後でbundle install –path=vendor/bundleをしてしまったため、rbenvの下のrubyの中にgemがどばどば入ったのと、railsアプリ内のvendor/bundleの下に入ったgemが一緒にロードされてしまったためです。
上の対処法では両方消した形になりますが、本当は片方だけで良いはず。
自分はついでに.bundle/configの中からBUNDLE
PATHを除去し、vendor/bundleではなくruby処理系の中に入れることにしました(自分のruby使用頻度だとそれであんま困らないので)_

同じくrbenvを使っているためにbundle install --path vendor/bundleをしてgemがごちゃごちゃになってしまったからだそうです。備忘録。