Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

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.

like image 537
tobu Avatar asked May 01 '14 06:05

tobu


6 Answers

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.

like image 153
tobu Avatar answered Nov 07 '22 17:11

tobu


rake rails:update:bin to the rescue.

like image 41
cisolarix Avatar answered Nov 07 '22 16:11

cisolarix


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
like image 13
jcraigk Avatar answered Nov 07 '22 17:11

jcraigk


This is work for me.

gem uninstall mysql2

bundle install or gem install mysql2

like image 6
kun Avatar answered Nov 07 '22 17:11

kun


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"
like image 4
gabriel Avatar answered Nov 07 '22 17:11

gabriel


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

like image 2
betoharres Avatar answered Nov 07 '22 15:11

betoharres