How to Check If a Port Is in Use on Mac
Find out which process is using a port on macOS with lsof, then stop it safely. Works on every recent macOS version.
You start a dev server and get EADDRINUSE: address already in use. Something is already listening on that port. Here is how to find it and free the port in under a minute.
Run lsof on the port
Open Terminal and run this, replacing 3000 with your port:
lsof -nP -iTCP:3000 -sTCP:LISTEN
lsof lists open files, and on Unix a network socket counts as a file. The flags mean: -n and -P skip slow hostname and port-name lookups, -iTCP:3000 limits results to TCP on port 3000, and -sTCP:LISTEN shows only processes actually listening.
If nothing prints, the port is free.
Read the output
A hit looks like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 48213 tyler 23u IPv6 0x1a2b3c 0t0 TCP *:3000 (LISTEN)
The two columns you care about are COMMAND (what it is) and PID (the process ID you will use to stop it).
Stop the process
Send it a normal termination signal using the PID from the previous step:
kill 48213
Most processes exit cleanly. If it is still there after a few seconds, force it:
kill -9 48213
Use -9 only as a fallback. It skips the process's cleanup, which can leave temp files or lock files behind.
Confirm the port is free
Run the first command again:
lsof -nP -iTCP:3000 -sTCP:LISTEN
No output means the port is yours. Start your server.
One-liner for next time. If you do this often, this finds and kills whatever is on the port in one step:
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)
-t prints only PIDs, which kill then receives. It errors harmlessly if the port is already free.
More Mac how-tos
- How to Change the Default Browser on Mac
- How to Check Which macOS Version You Have
- How to Find Your IP Address on Mac
- How to Flush the DNS Cache on Mac
- How to Force Quit an App on Mac
- How to Free Up Storage on Mac
- How to Generate an SSH Key on Mac
- How to Record Your Screen on Mac
- How to Show Hidden Files on Mac
- How to Take a Screenshot of Part of the Screen on Mac
- How to Uninstall an App on Mac
- How to Zip and Unzip Files on Mac