[Ruby] What to do if you get an A server is already running. error when trying to start rails server

less than 1 minute read

If you try to start rails server, the following error may be displayed and it may not be possible to start.

$ rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.2.4.2 application starting in development
=> Run `rails server -h` for more startup options
A server is already running. Check / directory path /tmp/pids/server.pid.
Exiting

This is an error because the server is already running. We will introduce the measures to be taken in this case.

kill PID of server.pid

Just kill the PID number in /tmp/pids/server.pid. Even if I delete the server.pid file manually, the server is still running, so Execute the following command, find the process running at 3000, and kill it.

$ lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby2.5 3033 vagrant 16u IPv4 27499 0t0 TCP *:3000 (LISTEN)

Kill the PID number found by the above command with the following command.

$ kill -9 3033

Now the server is off and you can start it successfully.

Reference article

https://qiita.com/motty93/items/d22c1eb8f5128f8cd7f8