Can't start Rails server - "Address In Use"


#1

Hello! May I kindly ask for help?

When I start rails server it gets loaded and then immediately exits like this:

[7112] * Listening on tcp://0.0.0.0:8080
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/puma-3.4.0/lib/puma/binder.rb:255:in `initialize’: Address already in use - bind(2) for “0.0.0.0” port 8080 (Errno::EADDRINUSE)

Is there any way out?
Thank you!


#2

run lsof -i :8080 to see processes that listen on that port, then run kill on that process.

you can use the following to do that automatically

openPort() {
    local PID=$(sudo lsof -t -i :$1)
    [ "$PID" != "" ] && sudo kill -9 $PID
    sleep 0.1
    echo killed $PID listening on $1: $(sudo lsof -t -i :$1)
}
openPort 8080

#3

Thank you so much! That’s very useful to know! I resolved this by restarting my workspace.