Rails Server Fails to Bind to Port Due to Another Process. How to Terminate the Process Using the Port? (Edited)

I am trying to start the web server for a Ruby on Rails application on Ubuntu 20.04 by running:

		
$ rails server

However, I get the following error:
		
=> Booting Puma => Rails 6.1.3.2 application starting in development => Run `bin/rails server --help` for more startup options Puma starting in single mode... * Puma version: 5.3.2 (ruby 2.7.4-p191) ("Birdie's Version") * Min threads: 5 * Max threads: 5 * Environment: development * PID: 12345 * Listening on http://127.0.0.1:3000 * Listening on http://[::1]:3000 => Booted puma (Server is running on http://127.0.0.1:3000 and http://[::1]:3000) Exiting /usr/local/lib/ruby/gems/2.7.0/gems/puma-5.3.2/lib/puma/binder.rb:277:in `initialize': Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)

I know I can run the Rails server on a different port, but how can I identify the processes that are blocking this port and terminate them?

David Johnson

11 days ago

1 answer

111 views

Rating

06
Answer

Answers

Oliver Williams

10 days ago

Edited

Rating

00

You can identify the processes using the port with the following command:

		
sudo lsof -i :

This will show all the processes using the specified .

Once you have the output, use the PID from the lsof -i command to gracefully terminate the unnecessary process:

		
sudo kill -15

If the process does not terminate gracefully, you can forcefully stop it with:

		
sudo kill -9

Reply