Skip to content
Edith

Guide

Fix Port Already in Use on Mac (EADDRINUSE)

What the error means, the usual culprit for each port, and how to fix it without killing the wrong thing.

Updated by

The short answer

The error means another process is already listening on the port your server wants. Find it first:

Terminal
lsof -nP -iTCP:3000 -sTCP:LISTEN

The COMMAND and PID columns tell you what it is. If it is an old copy of your own dev server, stop it with kill and the PID. If it is something you need, start your server on another port instead. The rest of this page goes through the common causes port by port, because the right fix depends on what is holding it. If you only want the stop command, the kill a process on a port guide has it.

What the error looks like

The wording depends on the runtime, but the cause is the same.

  • Node.js, Next.js, Express: an EADDRINUSE error with the address and port. Node's error reference describes it as an attempt to bind a server to a local address that is already in use.
  • Vite: no error by default. Vite moves to the next free port and prints the new address, so your browser tab on 5173 may be showing an old server. Set server.strictPort to make it fail instead.
  • Rails and Puma, Django, Flask, FastAPI: an "Address already in use" message from the operating system when the server tries to bind.
  • Docker: a message that the port is already allocated when a container publishes a port another container or a local process holds.
  • PostgreSQL, MySQL, Redis: the database logs that it could not bind its port, usually because another copy is already running.

Common causes by port

Port 3000: a dev server that never stopped

Next.js, Rails, Create React App and many Express apps default to 3000. The usual holder is the same app from earlier: a terminal tab you closed while the server kept running, a server started by your editor, or one a coding agent left behind. Check the working folder of the PID to be sure it is yours:

Terminal
lsof -nP -iTCP:3000 -sTCP:LISTENlsof -a -p 48213 -d cwd

Port 5000 or 7000: AirPlay Receiver

Built into macOS

Turn off AirPlay Receiver

Newer versions of macOS listen on 5000 and 7000 for AirPlay when AirPlay Receiver is on, which collides with Flask and some other frameworks that default to 5000. Killing it does not help, because macOS starts it again. Open System Settings, then General, then AirDrop & Handoff, and turn AirPlay Receiver off, or run your server on another port such as flask run --port 5001.

Port 5173: a second Vite server

Because Vite picks the next port on its own, two projects started in a row end up on 5173 and 5174. Look at the terminal output for the real address, or stop the older server so ports stay predictable.

Port 5432, 3306 or 6379: two copies of a database

A database installed with Homebrew, one from Postgres.app and one in a Docker container all want the same default port. Decide which one you use. Stop the Homebrew one with brew services stop and its formula name, quit Postgres.app from its menu, or publish the container on another host port, such as -p 5433:5432.

Port 8000 or 8080: Python, Java and proxies

Django, FastAPI with Uvicorn, python -m http.server, Spring and many local proxies use these. The fix is the same: find the holder, stop it if it is stale, or pass a different port.

Where the manual fix falls short

  • Hard to tell your servers apart. Several node or python processes give no hint which project they belong to without a second command.
  • Ports you cannot see. Without sudo, lsof hides processes of other users, so a port can look free and still fail.
  • It keeps happening. The error comes back every time a server is left running, and the fix is a command you have to remember.

The Edith way: Ports

Edith's local port viewer, Ports, keeps the answer one glance away. It lists every listening process grouped by project, labels what each server is, from Next.js and Vite to PostgreSQL and Docker, and marks servers that listen on every network interface as exposed. It labels AirPlay Receiver and never stops macOS services.

  1. 1

    Install Ports

    Open Library in Edith, find Ports and click Install. It appears under Developer in the sidebar.

  2. 2

    Find the holder

    Open Ports and look for the port from the error. Each row names the server, such as Next.js, Vite or PostgreSQL, with its project folder, so you know if it is yours before you touch it. The Dev servers filter hides everything else, and the All projects menu narrows the list to one project.

  3. 3

    Stop it, or open it

    If it is stale, click Stop and confirm. Edith asks it to exit and offers Force stop only if it does not. If it is the server you wanted all along, click Open to load it in your browser, or Copy address.

  4. 4

    Keep an eye on it

    The Ports widget on Home and the desktop lists running dev servers, so you notice the forgotten one before the next error.

From the terminal

When you are already in a terminal, who names the holder and kill frees the port; it only previews until you add --yes.

Terminal
ed ports who 3000ed ports kill 3000 --yes

Prefer free tools? The lsof commands above are built in, and PortKiller and the kill-port npm package are free and open source. Ports is worth it when you run several projects at once and want them labelled. It is part of Edith, $35 once for one Mac with every extension included, on macOS 14 or later on Apple silicon.

Common questions

Why does the port stay busy after I close the terminal?

Closing a window does not always stop the processes started in it, especially servers started in the background, by an editor, or by a process manager. Find the holder and stop it.

Should I just change the port?

If the holder is something you need, such as AirPlay Receiver or a database you use for another project, yes. If it is an old copy of the same app, stop it instead, or you will soon have two versions running.

Why does a port show as free but my server still fails?

Another user's process, often one started with sudo or a system service, holds it. Check with sudo lsof. Also make sure nothing else binds the same port on a different address, such as IPv6 only.

Can Ports tell me which project a server belongs to?

Yes. It reads each process's working folder and groups servers by project. The All projects menu at the top of the Ports page shows one project's servers at a time.

Related

Read how to kill a process on a port on Mac for the stop command in detail, and free disk space for developers for the next thing a busy dev Mac runs out of. See the pricing page for what an Edith license includes.

One app. Every tool your Mac is missing.

Pay once · No account · 30-day refund · macOS 14+ on Apple silicon