Tutorial

[Fix] Rails Server is Already Running

Pinterest LinkedIn Tumblr

Error

“A server is already running. Check …/tmp/pids/server.pid

This error means that the server is already running in the port you are trying to start the rails server on; normally 3000.

Reasons for Error

This error can occur in two cases:

  1. You are running the Rails server on port 3000 in another tab of the terminal
  2. You suspended the server abruptly
    This normally happens when you stop the server with ctrl+z instead of ctrl+c to exit the Rails server. ctrl+z suspends the process but doesn’t close the server running on port 3000 meaning the server is still running in the background. This can also happen when you close the terminal that the rails server was running on.

Solution

Rails server is running on port 3000 in another tab of the terminal

You can just close the server running on another tab on port 3000 to resolve this issue.

Server suspended abruptly

Solution for this case is to kill the process running in the background on port 3000

  1. Find the process id for the rails server port
    If the port you are running the rails server is different than 3000, you should replace 3000 with the port number as required.
       lsof -wni tcp:3000
    

    You should be able to see the output like this:

      COMMAND   PID USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
      ruby    16660 cool   14u  IPv4 0x89786e1f70a36a3      0t0  TCP 127.0.0.1:hbci (LISTEN)
      ruby    16660 cool   15u  IPv6 0x89786e1d82f7aeb      0t0  TCP [::1]:hbci (LISTEN)
    
  2. Copy value in PID column, here 16660
  3. Kill the process
       kill -9 16660
    

    You should see the following output:

       [1]  + 10975 killed     rails s
    
    1. Try running the server again

Conclusion

Rails server should be up and running without any errors now.

Thank you for reading. Happy Coding!

References

Avatar photo

Freelancing Software Developer | Ruby on Rails, Reactjs, React Native, Gatsby, Saas, Bootstrap | Traveller | Spiritual Practitioner

1 Comment

  1. Or add to your .zshrc file. Not original to me.

    alias killRails=’kill -9 $(lsof -i :3000 -t)’

    and type `killRails` in Terminal. Of course the name of the alias be anything you want.

Write A Comment