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

  1. Check one port

    Swap 8080 for the port you care about:

    lsof -nP -iTCP:8080 -sTCP:LISTEN

    The COMMAND and PID columns tell you what's listening. Leave off -sTCP:LISTEN (so lsof -nP -i :8080) to also see every connection to and from that port.

  2. See every listening port at once

    lsof -nP -iTCP -sTCP:LISTEN
    Example 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)

    *:3000 means it accepts connections from your network; 127.0.0.1:5173 means only from this Mac. Add sudo in front to include processes owned by root or other users.

  3. 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,etime,command -p 46210
    lsof -a -p 46210 -d cwd
  4. Decide what to do

    If it's yours and you don't need it, stop it with kill 46210 (and kill -9 only 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

PortUsually
3000Next.js, Express examples and many other Node dev servers by default
5173Vite's dev server by default
4321Astro's dev server by default
5000 and 7000macOS AirPlay Receiver (Control Center, shown as ControlCe)
5432PostgreSQL
6379Redis

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.

Related guides

Coming soon

Rather not do this by hand?

Spookle will show every dev server by port, repo and branch, with whether it's responding, so you never have to decode a PID again. It isn't out yet. Join the waitlist and we'll email you once, when it launches.