rails server bin / rails:6:警告:已经初始化常量APP_PATH错误

我使用的是Ubuntu 14.04,我是一个使用Ruby on Rails的初学者

我最近安装了rbenv,ruby 2.3.0和rails 4.2.4,教程如下: https ://gorails.com/setup/ubuntu/14.04

安装之后,我运行了ruby -v和rails -v,并获得了预期的版本。 到现在为止还挺好。 然后,我跑了rails s ,我得到了:

 rails server bin/rails:6: warning: already initialized constant APP_PATH error 

为了解决这个问题,我运行: rake rails:update:bin下面的这个StackOverflow问题: rails server bin / rails:6:warning:已经初始化常量APP_PATH错误导致了一个新的错误(我也删除了Spring gem):

 Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.5.0. Prepending `bundle exec` to your command may solve this. /my-home-directory/my-ruby-on-rails-project/config/boot.rb:3:in `<top (required)>' /my-home-directory/my-ruby-on-rails-project/config/application.rb:1:in `<top (required)>' /my-home-directory/my-ruby-on-rails-project/Rakefile:4:in `<top (required)>' LoadError: cannot load such file -- bundler/setup /my-home-directory/my-ruby-on-rails-project/config/boot.rb:3:in `<top (required)>' /my-home-directory/my-ruby-on-rails-project/config/application.rb:1:in `<top (required)>' /my-home-directory/my-ruby-on-rails-project/Rakefile:4:in `<top (required)>' (See full trace by running task with --trace) 

我预先安装了“bundle exec”,出现以下错误:

 /my-home-directory/my-ruby-on-rails-project/.bundle/gems/nokogiri-1.6.7.2/lib/nokogiri.rb:29:in `require': libruby.so.2.2: cannot open shared object file: No such file or directory - /my-home-directory/my-ruby-on-rails-project/.bundle/gems/nokogiri-1.6.7.2/lib/nokogiri/nokogiri.so (LoadError) from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/nokogiri-1.6.7.2/lib/nokogiri.rb:29:in `rescue in <top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/nokogiri-1.6.7.2/lib/nokogiri.rb:25:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/fog-1.23.0/lib/fog/xml.rb:1:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/fog-1.23.0/lib/fog/xml.rb:1:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/fog-1.23.0/lib/fog.rb:11:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/fog-1.23.0/lib/fog.rb:11:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:3:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:3:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave/storage.rb:9:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave/storage.rb:9:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave.rb:78:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/carrierwave-0.10.0/lib/carrierwave.rb:78:in `<top (required)>' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require' from /my-home-directory/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require' from /my-home-directory/my-ruby-on-rails-project/config/application.rb:7:in `<top (required)>' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `require' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `block in server' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /my-home-directory/my-ruby-on-rails-project/.bundle/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:8:in `require' from bin/rails:8:in `<main>' 

在安装rbenv之前,我使用了RVM,并且出现了相同的错误。 当我开始遇到这些问题时,我无法弄清楚我做了什么改变。

为了我的理智,任何帮助非常感谢!

谢谢你们!

我的一个朋友帮我解决了这个问题。 他建议:

  1. 在我的项目目录中用一行创建一个.ruby-version文件:ruby-2.3.0 – 这将确保我们不会加载另一个nokogiri版本
  2. 通过运行:rm -rfv .bundle来删除捆绑器
  3. 然后运行:捆绑
  4. 运行:bundle exec rails s

奇迹般有效。 我问他为什么认为我有这些问题,并说:很难说,一个乱七八糟的.bundle目录可以做很多时髦的东西。