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

前端 未结 12 2611
深忆病人
深忆病人 2020-12-02 03:26

I\'m on a mac, doing:

rails server

I get:

2010-12-17 12:35:15] INFO  WEBrick 1.3.1
[2010-12-17 12:35:15] INFO  ruby 1.8.7 (         


        
相关标签:
12条回答
  • 2020-12-02 03:58

    Using this command you can kill the server:

    ps aux|grep rails 
    
    0 讨论(0)
  • 2020-12-02 04:00

    If you are on windows machine follow these steps.

    c:/project/
    cd tmp
    c:/project/tmp
    cd pids
    c:/project/tmp/pids
    dir
    

    There you will a file called server.pid

    delete it.

    c:/project/tmp/pid> del *.pid
    

    Thats it.

    EDIT: Please refer this

    0 讨论(0)
  • 2020-12-02 04:01

    To kill process on a specific port, you can try this

    npx kill-port [port-number]

    0 讨论(0)
  • 2020-12-02 04:03

    One line solution:

    kill -9 $(ps aux | grep 'rails s' | awk {'print$2'}); rails s
    
    0 讨论(0)
  • 2020-12-02 04:06

    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.

    0 讨论(0)
  • 2020-12-02 04:06

    All the answers above are really good but I needed a way to type as little as possible in the terminal so I created a gem for that. You can install the gem only once and run the command 'shutup' every time you wanna kill the Rails process (while being in the current folder).

    gem install shutup

    then go in the current folder of your rails project and run

    shutup # this will kill the Rails process currently running

    You can use the command 'shutup' every time you want

    DICLAIMER: I am the creator of this gem

    NOTE: if you are using rvm install the gem globally

    rvm @global do gem install shutup
    
    0 讨论(0)
提交回复
热议问题