Skip to content
← Back to Blog
By Aaron Hampton Updated

'Address Already in Use' on Mac: Fix EADDRINUSE and Free the Port

Address already in use (EADDRINUSE) means another process holds the port, often port 3000. Here's how to find it on macOS, free the port, and stop it recurring.

You start a server and it dies immediately with bind: address already in use (or Address already in use, errno 48 on macOS). Node calls the same failure EADDRINUSE, Docker phrases it as “port 3000 is already allocated,” and you’ll also see it worded simply as “port already in use,” they’re all the same problem. The message is blunt but accurate: something already owns the port you’re trying to bind to. Here’s how to find it and get your port back.

What the error actually means

When a program wants to listen on a port, it calls bind() on that port number. If another socket is already bound there, the OS refuses with EADDRINUSE, “address already in use.” On macOS this is errno 48 (it’s 98 on Linux, in case you’re cross-referencing).

There are two possible causes, and the fix differs:

  1. Another process is still running and holding the port (almost always the answer).
  2. A recently closed socket is still in TIME_WAIT (rare, and only for servers that don’t set SO_REUSEADDR).

If you’re seeing EADDRINUSE from Node.js

Node’s version of this error looks like:

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:...)

Same failure, more detail. When your code calls app.listen(3000), it asks the OS to bind to port 3000, and if something already holds that port, the bind fails and Node surfaces EADDRINUSE. The :::3000 in the message is just the IPv6 form of “port 3000 on all interfaces.” Nine times out of ten in development, the culprit is a previous instance of your own server that never actually stopped. The fix is the same as the general case below.

Why port 3000 is already in use when you didn’t start anything

When a process exits, even after a crash or a force quit, the kernel closes its sockets and the port is free again. So if port 3000 is busy, something is almost always still running and holding it. The usual suspects:

  • A server you paused with Ctrl+Z instead of stopping with Ctrl+C. It’s suspended in the background but still owns the port.
  • A server orphaned when you closed its terminal tab or editor window, still running with no window attached.
  • A child process left behind by a watcher such as nodemon after the parent exited.
  • A Docker container that publishes port 3000.

This hits port 3000 more than any other because so many dev tools default to it (Next.js, Create React App, Rails, Express examples), and it’s easy to lose track of a server started in another tab. Underneath, the rule is simple: only one program can listen on a port at a time.

Step 1: Find what’s on the port

Replace 3000 with your port:

sudo lsof -i :3000 -n -P

If something owns it, you’ll see the process and PID:

COMMAND   PID   USER   ...  NODE NAME
node     1421  aaron   ...  TCP *:3000 (LISTEN)

Now you know node, PID 1421, is holding port 3000. The sudo matters: without it, lsof only shows your own processes and can come back empty even though something is listening. If the process name doesn’t ring a bell, see which app is using a port on Mac for how to track down what it actually is.

Do this more than once a month? Portie shows which app owns the port and kills it from the same window. $8.99 once, no subscription.

Step 2: Free the port

If that process is safe to stop (an old dev server, a forgotten script), kill it:

# Graceful first, lets it clean up
kill 1421

# If it won't go, force it
kill -9 1421

Or do it in one shot without copying the PID:

kill -9 $(lsof -ti tcp:3000 -sTCP:LISTEN)

The -t flag makes lsof print just the PID, which feeds straight into kill. See kill a process by port on Mac for when to prefer the graceful SIGTERM over the forceful SIGKILL. Once it’s dead, confirm the port actually cleared:

lsof -i :3000 -n -P

An empty result means it’s free. If something’s still there, you didn’t kill what you thought you did.

Two cases where a different fix is cleaner:

  • It’s a job you suspended in this terminal. Run jobs to see it, then fg to bring it back and stop it properly with Ctrl+C.
  • The owner is Docker (com.docker.backend or similar in the COMMAND column). Killing that takes down Docker itself. Run docker ps to find the container publishing the port, then docker stop it.

The TIME_WAIT case: nothing is on the port, but it’s still “in use”

Sometimes sudo lsof -i :3000 returns nothing, yet you still get “address already in use.” That can be TIME_WAIT: when a TCP connection closes, the OS keeps the socket reserved for a short cooldown (typically around 30 seconds on macOS) to make sure no stray packets from the old connection get misdelivered to a new one.

TIME_WAIT only blocks a new bind when the server doesn’t set the SO_REUSEADDR socket option. Node sets it by default, so for a Node server a busy port 3000 means a live process: go back to Step 1 and make sure you ran lsof with sudo. For other servers, you can confirm it:

netstat -an | grep 3000

If you see the port in TIME_WAIT rather than LISTEN, that’s what’s blocking the rebind. Two ways through it:

  • Just wait. The state clears on its own, usually within about 30 seconds on macOS.
  • Make your server reuse the address. Set SO_REUSEADDR, which lets a new socket bind to a port still in TIME_WAIT. Many frameworks expose it as a “reuse address” flag. This is the right long-term fix for servers you restart constantly.

Step 3: Or just change your port

If you can’t safely kill what’s holding the port, point your app somewhere else instead:

# Node
PORT=3001 npm start

# Vite (in vite.config or CLI)
npm run dev -- --port 5174

# Flask
flask run --port 5001

# Rails
rails server -p 3001

This works cleanly when your code reads the port from the environment, which it should:

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on ${port}`));

Moving your app is often safer than killing a process you can’t immediately identify, especially if the port belongs to a system service.

How each framework behaves when port 3000 is taken

Not every tool fails the same way, which is why a busy port 3000 sometimes looks like a different bug:

  • Next.js (next dev) warns that port 3000 is in use and quietly starts on 3001. Your app runs, but anything hardcoded to localhost:3000, such as an OAuth callback or an API base URL, now points at the old server.
  • Create React App (npm start) asks “Would you like to run the app on another port instead?” Answer yes and it moves to 3001.
  • Vite defaults to 5173, not 3000, and moves to the next free port if that’s taken. Set server.strictPort: true if you’d rather it fail loudly.
  • Express and plain Node servers don’t fall back. They crash with EADDRINUSE unless you handle the error (see below).
  • Rails fails with Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE). It can also refuse with “A server is already running” because of a leftover tmp/pids/server.pid. If Step 1 shows nothing on the port, that file is stale: delete it and start again.

If your app shows up on 3001 when you expected 3000, the old server on 3000 is still running. Free it with Step 2 rather than working around it.

Stop it from recurring

A few habits eliminate most repeat offenders, particularly on Node:

Handle the error instead of crashing blind. Catch it and print something useful:

const server = app.listen(port);
server.on('error', (err) => {
  if (err.code === 'EADDRINUSE') {
    console.error(`Port ${port} is already in use. Stop the other process or set a different PORT.`);
    process.exit(1);
  } else {
    throw err;
  }
});

Shut down cleanly on Ctrl-C so the port is released when you stop the server:

process.on('SIGINT', () => {
  server.close(() => process.exit(0));
});

Stop servers with Ctrl+C, not Ctrl+Z or by closing the tab. Those two leave the process running.

Use a process manager like pm2, or nodemon with the SIGINT handler above, so the old process actually exits and releases the port between restarts instead of leaving orphans behind.

The common offenders

Most “address already in use” errors trace back to a short list of usual suspects:

  • 3000 → Next.js, Create React App, Rails, Express (covered above)
  • 5000 → Flask, and AirPlay Receiver on macOS (port 5000 in use)
  • 8080 → Tomcat, proxies, second web apps (what is port 8080)
  • 8000 → Django, Python HTTP servers
  • 5173 → Vite
  • 4200 → Angular CLI
  • 5432 → PostgreSQL

The same lsof and kill commands work for all of them: swap the port number. The port reference covers what runs on each and whether it’s safe to kill.

One macOS-specific gotcha: port 5000 and 7000 are often held by AirPlay Receiver, not a program you started. If you can’t find your process on 5000, that’s usually why, turn off AirPlay Receiver in System Settings or just use a different port.

Find the culprit instantly

Portie shows every process holding a port on your Mac in one live table, so when you hit “address already in use,” you can see exactly what’s on that port without typing an lsof command, and end it with one click.

Local monitoring is free. The $8.99 one-time unlock adds one-click process termination (graceful or forced) and remote port scanning. Download Portie and never decode errno 48 by hand again.

Try Portie Free

See every open port on your Mac, which app owns it, and kill processes from the list.

Download Free