Port already in use on Mac: find what holds it and free it

Updated · 2 min read

Error: listen EADDRINUSE: address already in use :::3000 means another process already listens on that port. On a Mac, two commands find it and stop it:

bash
lsof -nP -iTCP:3000 -sTCP:LISTEN
kill 48213

Put your port in place of 3000, and the number from the PID column in place of 48213.

Find the process

bash
lsof -nP -iTCP:3000 -sTCP:LISTEN
text
COMMAND   PID   USER   FD   TYPE  DEVICE  SIZE/OFF NODE NAME
node    48213    you   23u  IPv6  0x9c…        0t0  TCP *:3000 (LISTEN)
  • -iTCP:3000 looks at TCP port 3000.
  • -sTCP:LISTEN keeps only the process that listens on it. Without it you also get every program connected to the port, your browser included.
  • -nP prints numbers instead of names, so it answers faster.

Most of the time it's a dev server started earlier in a terminal tab you've since closed, or one that kept running after the tool that started it quit.

Which project is it?

Several node processes look alike. These two tell them apart:

bash
ps -p 48213 -o command=
lsof -a -p 48213 -d cwd

The first prints the full command line. The second prints the folder the process runs in, in the NAME column.

Stop it

bash
kill 48213

kill asks the process to quit, so a server can close its connections first. If it's still listed a few seconds later:

bash
kill -9 48213

-9 can't be refused. Whatever the process hadn't saved is lost.

The one-liner, done safely

bash
lsof -tiTCP:3000 -sTCP:LISTEN | xargs kill

Many answers online give lsof -ti :3000 | xargs kill. That version also matches programs connected to port 3000: if the page is open in your browser, it can close the browser along with the server. Keep -sTCP:LISTEN in.

npx kill-port 3000 does the same from npm, if you prefer.

When it isn't a dev server

  • ControlCe on port 5000 or 7000 is the AirPlay Receiver of macOS. Don't kill it: it comes straight back. See Port 5000 in use on Mac.
  • A com.docker… process means a Docker container publishes the port. docker ps shows which one, and docker stop frees it.
  • Nothing is listed, but the port is still taken: the process belongs to another user or to the system, and lsof only shows it with sudo. Pick another port rather than stopping it.

Or use another port

Most dev servers take a port option or read the PORT variable: PORT=3001 npm start, next dev -p 3001, vite --port 5174. When you don't recognise what holds the port, that's often the safer move.

How Portroom handles it

Portroom says what holds the port, and offers the next one

Portroom checks a project’s port before it starts the server. When the port is taken, the project says by what, such as node · PID 48213 · not started by Portroom, with Kill process for your own processes and Use 8768, the next free port.

Processes lists dev servers left running outside your projects, with folder and command. Stopping one takes two clicks, and Portroom checks first that it’s still the same process.

A project in Portroom whose port 8765 is taken by node, with Kill process and Use 8768 buttonsA project in Portroom whose port 8765 is taken by node, with Kill process and Use 8768 buttons

Something wrong or out of date on this page? Write to support@portroom.dev.

More guides

Every dev server on your Mac, in one window.

Free for three servers at once, with 14 days of Pro first. No account.