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

匿名 (未验证) 提交于 2019-12-03 02:12:02

问题:

I've tried a number of things like uninstalling/reinstalling rails and gems but to no avail.

When I go into my new project and run rails s or bundle exec rails server I'm getting this error:

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:

#!/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?

回答1:

I couldn't find the an_initilizer.rb in my directory and I tried uninstalling/installing the spring gem but it didn't work.

However I did managed to finally get it working.

Apparently there is some conflict with spring and 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:

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.



回答2:

rake rails:update:bin to the rescue.



回答3:

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:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib 


回答4:

This is work for me.

gem uninstall mysql2

bundle install or gem install mysql2



回答5:

I was getting the same error. Removed spring from Gemfile and re-bundled. Not really a solution though.

I found the code that created this error in config/initializers/an_initializer.rb

require "lib/a_file_i_need" 

I changed it for

require "#{ Rails.root }/lib/a_file_i_need" 


回答6:

I got this error by trying to update rails 4 and imagemagick and rmagick. So I just ran

gem uninstall 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



回答7:

I received this error after upgrading postgresql.

$ gem uninstall pg $ gem install pg 

resolved this issue for me.



回答8:

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.

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 install recompiled the native extensions, and everything was running again.



回答9:

I got the same error. I had ruby 2.1.3 and rails 4.1.6 running on Mavericks and then I migrated to Yosemite and installed the 4.2.0 rails version an ruby 2.1.5 and my apps I made in the previous version didn't work with the new one, so I made some gem sets with RVM and installed the 2.1.3 version. Now when I wanted to run the server I got these error:

bin/rails:6: warning: already initialized constant APP_PATH /Users/Lexynux/_WebProjects/RoR_Apps/SAIIP2/bin/rails:6: warning: previous definition of APP_PATH was here Usage: rails COMMAND [ARGS] 

And as tobu mentioned I ran:

rake rails:update:bin 

I got this:

LoadError: dlopen(/Users/Lexynux/.rvm/gems/ruby-2.1.3@SAIIP2/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.16/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib 

Then I ran this:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib 

And finally I repeated the first command it the terminal asked me for this:

Overwrite /Users/Lexynux/_WebProjects/RoR_Apps/SAIIP2/bin/rails? (enter "h" for help) [Ynaqdh] 

I just typed 'Y' and hit return.

After all this I started working and going well.

Thanks.



回答10:

I got the same error, it happend to be related to gem dotenv. Instructions were to add the following to Gemfile:

gem 'dotenv', :require => 'dotenv/rails-now' 

But as it turned out, dotenv/rails-now caused the error. If you use dotenv don't require rails-now



回答11:

Are you using pg and mysql in different branches ? If yes, please confirm db config file.



回答12:

I'll post what worked for me.

Comment out

gem 'spring' 

Add gem 'net-shh'

and run bundle install

And restart your sever



回答13:

I received this error after upgrading rails. Disabling spring give me a hint that the issue was with:

gem 'google-api-client', require: 'google/api_client'

Changed to:

gem 'google-api-client', '0.9'

Resolved the issue.



回答14:

I had the same error message output when trying to start an application within a Vagrant environment. It cropped up out of nowhere after zero changes to the application code (and other weird behaviour followed, such as development.rb being deleted upon attempting to run the app).

In the end I simply halted the VM & restarted it, everything was then fine so I'm assuming it was an issue with file syncing / shared folders perhaps? (default Vagrant shared folder being used).



回答15:

Run these in console:

rake tmp:clear rake secret 


回答16:

IF rake rails:update:bin gives additional errors:

I had recently been doing some server maintenance and had subsequently updated OpenSSL.

When I tried running the rake rails:update:bin command, I was presented with an error relating to openSSL.

Having rebuilt my version of Ruby (`rvm reinstall ruby-x.x.x' with RVM), both errors went away.

This is always worth a try I guess.



回答17:

My problem was I was using an outdated version of ruby 1.9.3 with rails 4.2. I upgraded to 2.1.2 , removed the broken project, ran rails new blog to recreate my project, navigated into my newly created app and ran rails server and it worked.



回答18:

I just had this problem and found that it was being caused by the fact that I had removed a gem from the gemfile without deleting the other require references. In my case, I just had to remove it from config/application.rb.



回答19:

Had this error recently, it is caused by spring, because of its suggested code in executables:

begin   load File.expand_path('../spring', __FILE__) rescue LoadError end 

It originally expects a LoadError for spring itself in production, but by this code all other load error will be ignored too.

Thus if you have any other LoadError in rails loading process (for example in routes/init) spring worker startup fails and then there goes branch that tries to load everything again like there was no spring.



回答20:

For me this issue presented as a result of bundle upgrading rvm-capistrano amongst other things.
Adding this require:false fixed things in the end as per this previous post

gem  'rvm-capistrano',  require: false 

Although could possibly be an additional issue - as running rake rails:update:bin may have helped clear the initial issue.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!