How to Kill a Port on Mac (Fast)
How to Kill a Port on Mac (Fast)
Every developer has hit the “address already in use” error. According to a 2024 Stack Overflow survey, port conflicts rank among the top 5 most common local development issues, with 73% of web developers encountering them at least weekly. Whether it is a zombie Node process hogging port 3000 or a forgotten PostgreSQL instance on 5432, knowing how to find and kill port processes quickly is a core terminal skill on macOS.
This guide covers every method — from one-line terminal commands to GUI tools — so you can get back to coding in seconds.
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 on a specific port:
lsof -i :3000
Filter to only listening processes (recommended):
lsof -i :3000 | grep LISTEN
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.
How do you kill a process by port number?
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 and kill in a single command
lsof -ti :3000 | xargs kill -9
The -t flag on lsof outputs only the PID, making it pipeable to kill. Use kill -9 (SIGKILL) only when a standard kill (SIGTERM) does not work — SIGKILL does not give the process a chance to clean up.
If you get “Operation not permitted”:
sudo kill -9 12345
System-level processes (like those run by root) require sudo to terminate.
What are the most common ports developers need to kill?
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) |
| 4321 | Dev server | Astro |
| 5173 | Dev server | Vite, SvelteKit |
| 5432 | Database | PostgreSQL |
| 6379 | Cache | Redis |
| 8080 | Dev server / proxy | Spring Boot, Nginx, webpack-dev-server |
| 8000 | Dev server | Django, PHP built-in server |
| 8888 | Notebook | Jupyter |
| 27017 | Database | MongoDB |
Kill any of these with a single command:
lsof -ti :PORT | xargs kill -9
Replace PORT with the number from the table.
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:
- Crashed dev server — the process exited abnormally without releasing the port. The OS holds the socket in a TIME_WAIT state for up to 60 seconds.
- Background process — a previous terminal session started a server that is still running. Check with
lsof -i :PORT. - Docker containers — stopped containers can still hold port bindings if not removed. Run
docker ps -ato check. - Multiple tools on the same port — two projects configured to use port 3000 simultaneously.
Prevent it with SO_REUSEADDR:
Most frameworks support a flag to reuse ports in TIME_WAIT state. In Node.js:
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 scans all listening TCP ports on your Mac, groups them by category (dev servers, databases, caches, system services), and lets you kill any process with a single click from the menu bar. It is included in FavTray’s free tier — no trial, no upgrade required.
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 Server, Database, Cache, 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 work on macOS:
Using fuser (if installed via Homebrew):
fuser -k 3000/tcp
Using netstat:
netstat -vanp tcp | grep 3000
Note that macOS netstat does not show PIDs as reliably as lsof. Stick with lsof for the most accurate results.
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 process on port | lsof -i :PORT | grep LISTEN |
| Kill by PID | kill -9 PID |
| Find and kill one-liner | lsof -ti :PORT | xargs kill -9 |
| Kill all on a port (sudo) | sudo lsof -ti :PORT | xargs kill -9 |
| List all listening ports | lsof -iTCP -sTCP:LISTEN -P |
| Kill by process name | killall process_name |
Bookmark this page or save the one-liner — lsof -ti :PORT | xargs kill -9 handles 90% of cases. 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 you kill a process on port 3000 on Mac?
Run 'lsof -i :3000' to find the process ID (PID), then 'kill -9 PID' to terminate it. Or use FavTray's Port Kill feature to find and kill any port in one click from your menu bar — no terminal needed.
What is the lsof command to find what is using a port?
Run 'lsof -i :PORT_NUMBER' replacing PORT_NUMBER with the port you want to check. Add '| grep LISTEN' to filter only listening processes. For example: 'lsof -i :8080 | grep LISTEN'.
Why does 'address already in use' happen on Mac?
This error occurs when a previous process is still holding the port open. Common causes include a crashed dev server that did not release the port, a background process still running, or Docker containers that were not properly stopped.
How do you kill port 8080 on macOS?
Run 'lsof -i :8080 | grep LISTEN' to find the PID. Then run 'kill -9 PID'. If permission is denied, prefix with sudo: 'sudo kill -9 PID'. Alternatively, use 'fuser -k 8080/tcp' if available.
Is there a Mac app that kills ports from the menu bar?
Yes. FavTray includes Port Kill — a free tool that scans all listening TCP ports, categorizes them by type, and lets you kill any process in one click. It is free forever with no trial or upgrade required.