Kill Port on Mac: One Command for 3000 or Any Port
Short answer: to kill port 3000 on a Mac, run lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill in Terminal (swap 3000 for any other port). Use kill -9 only if the process ignores a normal kill. Keep the -sTCP:LISTEN part: without it, the popular lsof -ti :3000 | xargs kill also kills your browser’s connection to the dev server.
TL;DR
- Kill port 3000:
lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill(port 3000 fixes for Next.js and Rails) - See what is on a port first:
lsof -nP -iTCP:3000 -sTCP:LISTEN - “Operation not permitted”: put
sudobefore bothlsofandkill. - Port 5000 or 7000 busy: that’s macOS AirPlay Receiver, not your app (fix below).
- No Terminal: FavTray’s Port Kill lists every listening port in the menu bar; click to kill.
Every developer hits “address already in use” sooner or later: a Node server that did not shut down on port 3000, a forgotten PostgreSQL instance on 5432, a Flask app that collides with AirPlay on 5000. This guide covers the terminal commands, what each flag does, the macOS-specific causes, and a one-click option.
How do you find what is using a port on Mac?
The lsof (list open files) command is the standard tool for identifying which process holds a port. On macOS, network sockets are treated as files, so lsof covers both.
Find the process listening on a port (recommended):
lsof -nP -iTCP:3000 -sTCP:LISTEN
-iTCP:3000 limits the search to TCP port 3000, -sTCP:LISTEN keeps only the listening server, and -nP prints raw IP addresses and port numbers, which is faster.
Output example:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 12345 akash 23u IPv4 0x1234 0t0 TCP *:3000 (LISTEN)
The PID column (12345 in this example) is what you need to kill the process.
Why not plain lsof -i :3000? It matches every socket that uses port 3000 on either end, so it also lists clients connected to your dev server — usually your browser. That is harmless when you only read the output, and a problem when you pipe it into kill.
How do you kill a port on Mac (port 3000 and others)?
Once you have the PID, terminate it with kill:
## Graceful termination (try this first)
kill 12345
## Force kill (if graceful fails)
kill -9 12345
## One-liner: find the listening process and kill it
lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill
The -t flag on lsof outputs only the PID, making it pipeable to kill. Plain kill sends SIGTERM, which lets the server close connections and clean up. Use kill -9 (SIGKILL) only when the process is still there a few seconds later, since SIGKILL gives it no chance to clean up.
How do I kill port 3000 without killing my browser?
Keep -sTCP:LISTEN in the command. The one-liner copied around most often, lsof -ti :3000 | xargs kill -9, returns the PID of everything touching port 3000. If a browser tab has the dev server open, the browser’s networking process is in that list and gets force-killed along with the server. Filtering to the listening socket targets only the server.
If you get “Operation not permitted”, or lsof prints nothing but the port is still busy:
sudo lsof -nP -iTCP:3000 -sTCP:LISTEN
sudo kill 12345
Without sudo, lsof only shows your own processes, so a server run by root or another user is invisible.
Kill port 3000, 3001, 5173, 8080: common ports developers need to free
Different frameworks and services use different default ports. Here is a quick reference:
| Port | Common Service | Framework / Tool |
|---|---|---|
| 3000 | Dev server | React (CRA), Next.js, Rails, Express |
| 3001 | Secondary dev server | Next.js (when 3000 is taken) |
| 4000 | Dev server | Phoenix, Jekyll |
| 4321 | Dev server | Astro |
| 5000 | Dev server / AirPlay | Flask; also macOS AirPlay Receiver |
| 5173 | Dev server | Vite, SvelteKit |
| 5432 | Database | PostgreSQL |
| 6379 | Cache | Redis |
| 7000 | AirPlay | macOS AirPlay Receiver |
| 8000 | Dev server | Django, PHP built-in server |
| 8080 | Dev server / proxy | Spring Boot, Nginx (Homebrew), webpack-dev-server |
| 8888 | Notebook | Jupyter |
| 27017 | Database | MongoDB |
Kill any of these with a single command:
lsof -ti tcp:PORT -sTCP:LISTEN | xargs kill
Replace PORT with the number from the table.
Port 5000 or 7000 in use? That’s AirPlay Receiver
Since macOS Monterey, the Mac can act as an AirPlay receiver, and it listens on ports 5000 and 7000 to do it. In lsof it appears as ControlCenter (shortened to ControlCe):
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 635 akash 11u IPv4 0x4499 0t0 TCP *:5000 (LISTEN)
Don’t kill it: Control Center restarts and takes the port back. Instead, either:
- Turn it off: System Settings > General > AirDrop & Handoff > AirPlay Receiver, or
- Move your app:
flask run --port 5001, or setPORT=5001for other frameworks.
Why does “address already in use” keep happening?
This error means a process is still bound to the port you are trying to use. The most common causes:
- A dev server that did not shut down — closing a terminal tab or a crashed watcher can leave the server process running.
lsof -nP -iTCP:PORT -sTCP:LISTENfinds it. - A server started elsewhere — another terminal, an IDE run configuration, or a background job.
- Docker containers — a running container that publishes the port shows up in
lsofas a Docker Desktop process (its name starts withcom.docker), not as your app. Don’t kill that; find the container withdocker psand stop it withdocker stop <container>. - AirPlay Receiver — ports 5000 and 7000, covered above.
- Two projects on the same port — two projects configured to use port 3000 at the same time.
If lsof shows nothing: first re-run it with sudo, because the process may belong to another user or to root. If it is still empty, the port is probably held by a just-closed connection in TIME_WAIT. Those have no owning process, so lsof can’t show them, but netstat -an -p tcp | grep '\.3000 ' will. On macOS TIME_WAIT lasts 30 seconds (twice the net.inet.tcp.msl value of 15,000 ms), and servers that set SO_REUSEADDR, as Node does, can usually rebind straight away.
Fall back to the next port in Node.js:
If a port clash is routine for a project, let the server move instead of failing:
server.listen(3000, () => {}).on('error', (e) => {
if (e.code === 'EADDRINUSE') {
console.log('Port 3000 in use, trying 3001...');
server.listen(3001);
}
});
Is there a faster way than the terminal?
Yes. If you kill ports regularly, a GUI tool saves time and eliminates the need to remember command syntax.
FavTray’s Port Kill lists every listening TCP port on your Mac, groups the processes by type, and lets you kill any of them with a click from the menu bar. Because it only lists listening sockets, your browser’s connections never appear in it. It tries a normal kill first and offers a force kill if the process ignores it; for a process owned by root, it copies the sudo kill command for you to paste into Terminal. Listing, search and filters are free with no limit, and the free plan includes 10 kills a day; the one-time Lifetime licence (pricing) removes the cap.
What Port Kill shows you:
| Column | Description |
|---|---|
| Port | The TCP port number |
| Process | The process name (node, postgres, redis-server) |
| PID | Process ID for reference |
| Category | Auto-detected: Dev Servers, Python, Java, Docker, Databases, Web Servers, System |
| Action | One-click kill button |
Port Kill is particularly useful when you have multiple stale processes across different ports — instead of running lsof five times, you see everything at a glance.
What about other terminal alternatives?
Beyond lsof and kill, a few other tools come up in answers online:
fuser doesn’t work for this on macOS. The fuser -k 3000/tcp command from Linux guides fails here: macOS’s /usr/bin/fuser has no -k option and doesn’t accept ports.
Using netstat:
netstat -anv -p tcp | grep '\.3000 '
This shows every TCP socket on port 3000, including ones in TIME_WAIT, and on recent macOS versions -v adds the process name and PID. It is useful for seeing socket states; lsof -t is still the easier way to pipe a PID into kill.
Using killall by process name:
killall node
This kills all node processes, not just the one on a specific port. Use it carefully.
Quick reference cheat sheet
For the commands you will actually use day-to-day:
| Task | Command |
|---|---|
| Find the listener on a port | lsof -nP -iTCP:PORT -sTCP:LISTEN |
| Kill by PID | kill PID (then kill -9 PID if needed) |
| Find and kill one-liner | lsof -ti tcp:PORT -sTCP:LISTEN | xargs kill |
| Same, for root or another user | sudo lsof -ti tcp:PORT -sTCP:LISTEN | xargs sudo kill |
| List all listening ports | lsof -nP -iTCP -sTCP:LISTEN |
| Kill by process name | killall process_name |
Save the one-liner — lsof -ti tcp:PORT -sTCP:LISTEN | xargs kill frees the port without taking your browser with it. For a zero-terminal workflow, FavTray’s Port Kill puts all your active ports in one menu bar panel. It pairs well with FavTray’s other developer tools, consolidating port management alongside system monitoring, window snapping, and break reminders in a single icon.
Frequently Asked Questions
How do I kill port 3000 on a Mac?
Run 'lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill' in Terminal. It finds only the process listening on port 3000 and asks it to quit. If it is still running a few seconds later, repeat with 'kill -9'. Or use FavTray's Port Kill to see every listening port in your menu bar and kill one with a click.
What does 'lsof -ti :3000 | xargs kill' do?
lsof -ti :3000 prints the process ID of every process with a socket on port 3000, and xargs kill sends each of them a termination signal. That includes the dev server, but also any client connected to it, such as your browser. Adding -sTCP:LISTEN ('lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill') limits it to the server that is listening on the port.
How do I kill the process on a port in one command on Mac?
Use 'lsof -ti tcp:PORT -sTCP:LISTEN | xargs kill', replacing PORT with the number, for example 5173 for Vite or 8000 for Django. To make it a reusable command, add a shell function to ~/.zshrc: killport() { lsof -ti tcp:$1 -sTCP:LISTEN | xargs kill; } and then run 'killport 3000'.
How do I kill port 3000 without killing my browser?
Add -sTCP:LISTEN to lsof. 'lsof -i :3000' matches every socket that uses port 3000, including your browser's open connection to the dev server, so piping it to kill can take down the browser too. 'lsof -ti tcp:3000 -sTCP:LISTEN | xargs kill' only targets the server that is listening on the port.
What is the lsof command to find what is using a port?
Run 'lsof -nP -iTCP:PORT -sTCP:LISTEN', replacing PORT with the port number, for example 'lsof -nP -iTCP:8080 -sTCP:LISTEN'. It shows the command name, PID and user of the process listening on that port. If nothing prints but the port is still busy, run it again with sudo: the process may belong to another user or to root.
Why does 'address already in use' happen on Mac?
Something is still listening on the port: a dev server that did not shut down, a server started in another terminal, a Docker container that publishes the port, or on ports 5000 and 7000, macOS's AirPlay Receiver. If lsof shows nothing, the port is either held by another user's process (check with sudo lsof) or a just-closed connection in TIME_WAIT, which clears within 30 seconds on macOS.
What is using port 5000 on my Mac?
On macOS Monterey and later, it is usually AirPlay Receiver, which listens on ports 5000 and 7000 and shows up in lsof as ControlCenter. Turn it off in System Settings > General > AirDrop & Handoff > AirPlay Receiver, or run your app on another port, for example 'flask run --port 5001'.
How do you kill port 8080 on macOS?
Run 'lsof -ti tcp:8080 -sTCP:LISTEN | xargs kill'. If the process ignores it, use 'kill -9' instead. If you get 'Operation not permitted', the process belongs to root or another user: run 'sudo lsof -ti tcp:8080 -sTCP:LISTEN | xargs sudo kill'.
Is there a Mac app that kills ports from the menu bar?
Yes. FavTray's Port Kill lists every listening TCP port with its process, groups them by type (dev servers, Python, Java, Docker, databases, web servers, system), and kills the one you pick with a click. It tries a normal kill first and offers a force kill if the process ignores it. Listing and searching ports is free with no limit, and the free plan includes 10 kills a day, reset at local midnight.