Mac how-to
How to find what’s using a port on a Mac
Updated · Tested commands for macOS Terminal (zsh or bash)
Something is sitting on a port you need, and the error doesn't say what. macOS ships with lsof, which can tell you in one command. Here's how to use it for one port or all of them, and how to work out which project a process belongs to.
Quick answer
Run this in Terminal, swapping in your port number. The PID column is the process to look at.
lsof -nP -iTCP:3000 -sTCP:LISTEN
Step by step
-
Check one port
Swap 8080 for the port you care about:
lsof -nP -iTCP:8080 -sTCP:LISTENThe
COMMANDandPIDcolumns tell you what's listening. Leave off-sTCP:LISTEN(solsof -nP -i :8080) to also see every connection to and from that port. -
See every listening port at once
lsof -nP -iTCP -sTCP:LISTENExample output (example data) COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ControlCe 612 you 10u IPv4 0x3c4d 0t0 TCP *:5000 (LISTEN) node 46210 you 21u IPv6 0x1a2b 0t0 TCP *:3000 (LISTEN) node 47733 you 24u IPv4 0x5e6f 0t0 TCP 127.0.0.1:5173 (LISTEN)*:3000means it accepts connections from your network;127.0.0.1:5173means only from this Mac. Addsudoin front to include processes owned by root or other users. -
Find out which project it belongs to
A PID on its own doesn't tell you much. These show the full command and the folder it was started in:
ps -o pid,ppid, -p 46210etime, command lsof -a -p 46210 -d cwd -
Decide what to do
If it's yours and you don't need it, stop it with
kill 46210(andkill -9only if it won't quit). Our port 3000 guide walks through it. If it's a macOS service, leave it and use another port.
Ports you'll often see on a Mac
| Port | Usually |
|---|---|
| 3000 | Next.js, Express examples and many other Node dev servers by default |
| 5173 | Vite's dev server by default |
| 4321 | Astro's dev server by default |
| 5000 and 7000 | macOS AirPlay Receiver (Control Center, shown as ControlCe) |
| 5432 | PostgreSQL |
| 6379 | Redis |
These are common defaults, not rules. Always check with lsof rather than guessing.
Prefer clicking? Activity Monitor can help
Open Activity Monitor, double-click a process and choose the Open Files and Ports tab to see the ports it has open. It works one process at a time, so it's slower than lsof for finding who holds a particular port. To stop a process there, select it and use the stop button in the toolbar. Apple's guide explains Quit and Force Quit.
Questions
Why is port 5000 or 7000 taken on my Mac?
On macOS Monterey and later, AirPlay Receiver listens on 5000 and 7000 through Control Center. Killing it doesn't stick because macOS restarts it. Turn off AirPlay Receiver in System Settings, General, AirDrop and Handoff, or pick another port.
Why does lsof show nothing, but the port is still busy?
The process probably belongs to another user or root, which lsof can't see without sudo. Run the same command with sudo in front. Also check docker ps, since a container can publish the port.
What do -n and -P do in lsof?
-n skips turning IP addresses into hostnames and -P skips turning port numbers into service names, so you see :3000 instead of a name, and the command runs faster.
How do I check a UDP port?
Use -iUDP instead, for example lsof -nP -iUDP:5353. UDP has no listening state, so leave off -sTCP:LISTEN.