To check if a port is in use, run this command (replacing 3000 with your port number):

lsof -i :3000

If something is using that port, you'll see output like:

COMMAND   PID   USER   FD   TYPE   DEVICE   SIZE/OFF   NODE   NAME
node    12345   you   23u   IPv4   0x...    0t0        TCP    *:3000 (LISTEN)

If nothing is using the port, you'll see no output at all.

What the Output Means

Column Meaning
COMMAND The program using the port (node, python, etc.)
PID Process ID - use this to kill it
USER Who started the process
NAME The port and connection state

The important parts: COMMAND tells you what's running, PID tells you how to stop it.

How to Kill the Process

If you want to free up the port, use the PID from the output:

kill -9 12345

Replace 12345 with the actual PID. The -9 forces the process to stop immediately.

One Command to Find and Kill

If you want to do both in one line:

lsof -ti :3000 | xargs kill -9

This finds the process and kills it immediately. Use with caution - make sure you actually want to kill whatever is running.

Common Ports

Port Usually Used By
3000 Node.js, Rails, React dev servers
5000 Flask, many dev servers
8000 Django, Python HTTP servers
8080 Alternative HTTP, Tomcat, Jenkins
5432 PostgreSQL
3306 MySQL
27017 MongoDB
6379 Redis

Why "Address Already in Use" Happens

You're seeing this because:

  1. Another instance of your app is running. Maybe you started a server earlier and forgot to stop it.

  2. A previous process didn't shut down cleanly. It crashed but didn't release the port.

  3. Another app uses that port. Two different applications trying to use the same port.

The fix is always the same: find what's using the port and stop it.

Check Multiple Ports at Once

lsof -i :3000 -i :8080 -i :5000

This checks ports 3000, 8080, and 5000 in one command.

See All Listening Ports

To see everything that's listening on any port:

lsof -i -P | grep LISTEN

This gives you a full picture of what's running network services on your Mac.

If You Get "Permission Denied"

Some processes run as root (the system administrator). To see them, add sudo:

sudo lsof -i :80

Port 80 (HTTP) often requires this because it's a privileged port.

Alternative: Using netstat

You can also use netstat:

netstat -an | grep 3000

This works but doesn't show you the process name as clearly. lsof is more useful for finding what to kill.

Common Mistakes

Forgetting the colon: It's lsof -i :3000, not lsof -i 3000. The colon is required.

Wrong port number: Double-check the port in your error message. If it says "port 3001 already in use," search for 3001.

Killing the wrong thing: Look at the COMMAND column before running kill. Make sure it's actually something you want to stop.

Prevent This in the Future

If this keeps happening:

  • Use different ports: Configure your apps to use non-conflicting ports
  • Clean shutdown: Stop servers properly with Ctrl+C instead of closing the terminal
  • Check before starting: Run the lsof check before launching your app

Keep Learning

Port conflicts are a common annoyance when developing locally. Understanding processes, ports, and how to manage them makes your workflow smoother.

For a complete Terminal foundation, check out the free course at Mac Terminal for Humans.