..$ rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=>
SOLVING
Address already in use — bind(2)” 500 error in Ruby on Rails
Recently I tried running a Rails app on a production server. Not only did it not work, but it broke my localhost:3000 development server as well. Localhost would only load a blank white page or a 500 error.
To solve this, I used two quick commands. If these don’t return a result, you may need to look elsewhere for a solution, but this is a good quick fix.
lsof -wni tcp:3000
ruby 52179 rachelchervin 50u IPv6 0x...7aa3 0t0 TCP [::1]:hbci (LISTEN) ruby 52179 rachelchervin 51u IPv4 0x...c7bb 0t0 TCP 127.0.0.1:hbci (LISTEN) ruby 52180 rachelchervin 50u IPv6 0x...7aa3 0t0 TCP [::1]:hbci (LISTEN) ruby 52180 rachelchervin 51u IPv4 0x...c7bb 0t0 TCP 127.0.0.1:hbci (LISTEN)
This command shows all of my currently running processes and their PIDs (process IDs) on the 3000 port. Because there are existing running processes that did not close correctly, my new :3000 server can’t start, hence the 500 error.
kill 52179
kill 52180
rails s
I used the Linux kill command to manually stop the offending processes. If you have more than 4, simply use kill on any PIDs until the first command comes back blank. Then, try restarting your localhost:3000 server again. This will not damage your computer! It simply kills existing ruby processes on your localhost port. A new server will start these processes all over again. Good luck!