How to remove a port in use on mac

How to remove a port in use on mac

This is what happened to me during my first ever attempt to run python flask server on my Macbook.

Python Flask default port number is set to 5000. As I started running the server on the terminal, it prompted an error message saying OSError: [Errno 48] Address already in use.

Don't worry and just follow this step-by-step guide if this happens to you.

  1. using Cmd + space, search Network Utility.app and open it
  2. on the app, you will see port scan menu.
  3. type your localhost ip address ex) 127.0.0.1 and click scan button
  4. if you see the 5000 port number, yeah that's what it is
  5. on terminal, run lsof -i tcp:5000
  6. now you will see PID(Process ID) number then, copy it.
  7. on terminal, run kill -9 <PID>

Once you complete it, you can try to run the flask server again.