DEV Community

Edgar Carrillo
Edgar Carrillo

Posted on

How to find and kill a process locking a port on Mac

Introduction

Many of us have probably tried running our server on a port such as localhost:3000 or development environment on the same port.

There's also the time where we closed our terminal without killing our port. This brings up a:

EADDRINUSE: address already in use :::3000
Enter fullscreen mode Exit fullscreen mode

...error message (your port number could be different)

This quick guide will show you how to find the port and kill it in two simple commands.

Steps

  1. Get the PID of the port you want to kill. In terminal type the following
sudo lsof -i :3000 # The port # here should be the one giving issue
Enter fullscreen mode Exit fullscreen mode

A series of information should appear on your screen. Take note of the PID number.

  1. Type the following command to kill the port with the PID you specified:
kill -9 <PID>
Enter fullscreen mode Exit fullscreen mode

Conclusion

Now since you killed the port you should be free to reuse it!

References

Top comments (0)