Ruby-on-rails rails server bin/rails:6: 警告: 已初始化常量 APP_PATH 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23402820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rails server bin/rails:6: warning: already initialized constant APP_PATH error
提问by tobu
I've tried a number of things like uninstalling/reinstalling rails and gems but to no avail.
我尝试了很多方法,例如卸载/重新安装 rails 和 gems,但都无济于事。
When I go into my new project and run rails s or bundle exec rails server I'm getting this error:
当我进入我的新项目并运行 rails s 或 bundle exec rails server 我收到此错误:
bin/rails:6: warning: already initialized constant APP_PATH
/Users/toabui/Sites/cms/bin/rails:6: warning: previous definition of APP_PATH was here Usage: rails COMMAND [ARGS]
Inside my bin/rails I see this code:
在我的 bin/rails 中,我看到了以下代码:
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
Does anyone know why I keep getting that error when I run rails s?
有谁知道为什么我在运行 rails 时总是收到那个错误?
I've googled and it seems like there is an error with the spring gem but I can?t seem to get it to work.
我用谷歌搜索过,似乎 spring gem 有错误,但我似乎无法让它工作。
回答by tobu
I couldn't find the an_initilizer.rb in my directory and I tried uninstalling/installing the spring gem but it didn't work.
我在我的目录中找不到 an_initilizer.rb 并且我尝试卸载/安装 spring gem 但它没有用。
However I did managed to finally get it working.
但是我确实设法最终让它工作。
Apparently there is some conflict with spring and rails 4+.
显然与 spring 和 rails 4+ 存在一些冲突。
I needed to run:
我需要运行:
rake rails:update:bin
But I ran across another error:
但我遇到了另一个错误:
Library not loaded: libmysqlclient.18.dylib
I ran the following command which I found on another stackoverflow post:
我运行了在另一个 stackoverflow 帖子中找到的以下命令:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Then ran the original command:
然后运行原始命令:
rake rails:update:bin
Then run the server command:
然后运行服务器命令:
rails s
And now my WebBrick Server is running.
现在我的 WebBrick 服务器正在运行。
回答by cisolarix
rake rails:update:binto the rescue.
rake rails:update:bin到救援。
回答by jcraigk
If you are on El Capitan (OS X 10.11), Security Integrity Protection (SIP) will prevent linking into /usr/lib to fix mysql. Link it into /usr/local/lib instead:
如果您使用 El Capitan (OS X 10.11),安全完整性保护 (SIP) 将阻止链接到 /usr/lib 以修复 mysql。将其链接到 /usr/local/lib 代替:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
回答by kun
This is work for me.
这对我来说是工作。
gem uninstall mysql2
gem uninstall mysql2
bundle installor gem install mysql2
bundle install或者 gem install mysql2
回答by gabriel
I was getting the same error. Removed spring from Gemfile and re-bundled. Not really a solution though.
我遇到了同样的错误。从 Gemfile 中移除 spring 并重新捆绑。虽然不是真正的解决方案。
I found the code that created this error in config/initializers/an_initializer.rb
我在中找到了创建此错误的代码 config/initializers/an_initializer.rb
require "lib/a_file_i_need"
I changed it for
我改变了它
require "#{ Rails.root }/lib/a_file_i_need"
回答by betoharres
I got this error by trying to update rails 4 and imagemagick and rmagick. So I just ran
我通过尝试更新 rails 4 以及 imagemagick 和 rmagick 得到了这个错误。所以我就跑了
gem uninstall rmagick
gem 卸载 rmagick
Select the All Versions option. Then try again
选择所有版本选项。然后再试一次
EDIT: This happaned again with me just now because I tried to use a gem without installing the required base gem. In my case the solution was to install 'omniauth-google' before trying to use 'omniauth-google-oauth2', but because I didn't install I got the same error again
编辑:这又发生在我身上,因为我试图在没有安装所需的基础 gem 的情况下使用 gem。在我的情况下,解决方案是在尝试使用“omniauth-google-oauth2”之前安装“omniauth-google”,但因为我没有安装,我再次遇到了同样的错误
回答by Ryan Doom
I received this error after upgrading postgresql.
升级 postgresql 后我收到此错误。
$ gem uninstall pg
$ gem install pg
resolved this issue for me.
为我解决了这个问题。
回答by amiuhle
This happened to me after doing a brew upgrade. My guess is that this broke some gems with native extensions, even though there was no error message pointing to that.
这发生在我做了一个brew upgrade. 我的猜测是这破坏了一些带有本机扩展的 gem,即使没有指向它的错误消息。
What I ended up doing was completely removing my installed gems (In my case I completely uninstalled and reinstalled the ruby version using rbenv).
Running bundle installrecompiled the native extensions, and everything was running again.
我最终做的是完全删除我安装的 gems(在我的情况下,我完全卸载并使用 重新安装了 ruby 版本rbenv)。
运行bundle install重新编译本机扩展,一切都再次运行。
回答by antonpot
I got the same error, it happend to be related to gem dotenv.
Instructions were to add the following to Gemfile:
我遇到了同样的错误,它恰好与gem dotenv. 说明是将以下内容添加到 Gemfile:
gem 'dotenv', :require => 'dotenv/rails-now'
But as it turned out, dotenv/rails-nowcaused the error. If you use dotenvdon't require rails-now
但事实证明,dotenv/rails-now导致了错误。如果您使用dotenv不需要rails-now
回答by ysk
Are you using pg and mysql in different branches ? If yes, please confirm db config file.
你在不同的分支中使用 pg 和 mysql 吗?如果是,请确认数据库配置文件。

