Rails server says port already used, how to kill that process?

ID : 10196

viewed : 15

Tags : ruby-on-railsruby-on-rails

Top 5 Answer for Rails server says port already used, how to kill that process?

vote vote

100

Assuming you're looking to kill whatever is on port 3000 (which is what webrick normally uses), type this in your terminal to find out the PID of the process:

$ lsof -wni tcp:3000 

Then, use the number in the PID column to kill the process:

$ kill -9 PID 
vote vote

87

kill -9 $(lsof -i tcp:3000 -t)

vote vote

72

You need to get process id of program using tcp port 3000. To get process id

lsof -i tcp:3000 -t 

And then using that process id, simply kill process using ubuntu kill command.

kill -9 pid 

Or just run below mentioned combine command. It will first fetch pid and then kill that process.

kill -9 $(lsof -i tcp:3000 -t) 
vote vote

63

For anyone stumbling across this question that is not on a Mac: assuming you know that your server is running on port 3000, you can do this in one shot by executing the following:

fuser -k 3000/tcp 

But as Toby has mentioned, the implementation of fuser in Mac OS is rather primitive and this command will not work on mac.

vote vote

55

Some times there is a chance where rails server not closed properly. You can find process used by rails

ps aux | grep rails

Output will be like

user     12609  9.8  0.5  66456 45480 pts/0    Sl+  21:06   0:02 /home/user/.rvm/rubies/ruby-2.2.0-preview1/bin/ruby bin/rails s 

Here process_id 12609 is used by your rails server.

You can kill it easily by command

kill -9 12609

Top 3 video Explaining Rails server says port already used, how to kill that process?

Related QUESTION?