Port 3000 already in use? Find and free it on macOS
You run npm run dev and get Error: listen EADDRINUSE: address already in use :::3000. Or Rails says the address is in use, or Flask fails on port 5000. Something on your Mac is already listening on that port, and you need to find out what it is before you can free it.
Usually it is a dev server you started earlier in another terminal tab, or one that kept running after its window closed. Sometimes it is a database, a Docker container or macOS itself. Here is how to find out which, and how to stop it safely.
Find what is using the port
macOS ships with lsof, which lists open files, and on macOS network sockets count as files. To see what is listening on port 3000:
lsof -nP -iTCP:3000 -sTCP:LISTEN
The output looks like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 48213 you 23u IPv6 0x... 0t0 TCP *:3000 (LISTEN)
What the parts mean:
-iTCP:3000limits the list to TCP sockets on port 3000.-sTCP:LISTENshows only sockets waiting for connections, not your browser’s connections to them.-nand-Pprint numeric addresses and ports, which is faster and avoids confusing names.- COMMAND and PID tell you what to stop. NAME shows the address:
*:3000means every network interface,127.0.0.1:3000means this Mac only.
node alone doesn’t say much when you have five projects open. To see the full command line and the folder it was started from:
ps -o command= -p 48213
lsof -a -p 48213 -d cwd -Fn
The second command prints the process’s working folder after an n, which is usually the project folder.
To list every port in use at once, drop the port number:
lsof -nP -iTCP -sTCP:LISTEN
Stop the process
Once you know the PID, ask the process to quit:
kill 48213
kill without options sends SIGTERM, a polite request. Dev servers, databases and most other programs catch it, close their connections, write what they need to disk and exit. Give it a few seconds, then run the lsof command again to check that the port is free.
If the process ignores SIGTERM, force it:
kill -9 48213
SIGKILL ends the process immediately, without any cleanup. That is fine for a hung dev server, but for a database it is like pulling the plug: it will usually recover, but unsaved work can be lost. Use it only when a normal kill didn’t work.
You can also find and stop in one line. This sends SIGTERM to every process listening on port 3000, so look at the lsof output first if you are not sure what is there:
kill $(lsof -ti tcp:3000 -sTCP:LISTEN)
When the port doesn’t free up
It comes back after you stop it
If a new process grabs the port a second later, something is restarting it. Common causes:
- Homebrew services: PostgreSQL, Redis or MySQL started with
brew services start. Stop them withbrew services stop postgresql@16(use the namebrew services listshows), or they come back. - A process manager: pm2, nodemon or a
launchdjob. Stop it through the manager, for examplepm2 stop all. - A dev server in a terminal tab you forgot about: look for it and press Control-C there.
lsof shows nothing, but the port is still busy
lsof only shows your own processes. A port held by a process that runs as root or as another user doesn’t appear unless you use sudo:
sudo lsof -nP -iTCP:5432 -sTCP:LISTEN
Stopping that process needs sudo kill too. Be sure what it is first: a root process on a port is often a system service or something installed with an installer package.
It’s Docker
If the command is com.docke (lsof cuts names to 9 characters; the full name is com.docker.backend), the port is published by a container. Stopping the Docker process would stop all your containers. Stop just that container instead:
docker ps --format '{{.Names}}\t{{.Ports}}'
docker stop <container-name>
It’s macOS: port 5000 and 7000
On recent macOS versions, port 5000 and 7000 are often taken by ControlCenter. That is AirPlay Receiver, which lets other devices stream to your Mac, and it collides with Flask’s default port. You can’t kill it; turn it off in System Settings › General › AirDrop & Handoff › AirPlay Receiver, or run your app on another port.
Caveats
- Stopping a process closes every port it has, not just the one you looked up. A dev server started with
--inspectalso holds a debugger port, usually 9229. - Don’t stop processes you don’t recognise just because they hold a port.
rapportd,mDNSResponderandControlCenterare part of macOS. kill -9andsudo killare hard to undo. A database stopped that way may need to recover on its next start.- If you only need the app to run now, starting it on another port is often quicker:
PORT=3001 npm run dev,vite --port 3001,rails s -p 3001.
The faster way: CCToolify
The Ports tool in CCToolify keeps a live list of every port in use, with the app, the project folder or the Docker container behind it, and who can connect.
- Type 3000 in the search field, or use Free a Port…: type a port, see which app is using it, then Stop.
- Stop asks the app to quit first. If it is still running after 5 seconds, CCToolify offers Force Stop.
- Databases ask before stopping, because the apps that use them lose their connection.
- Docker ports show the container name. Stop on a Docker row quits Docker itself, so every running container stops and CCToolify asks first. To stop one container, use
docker stopas shown above. - Ports owned by macOS show Used by macOS and where to turn them off, such as the AirPlay Receiver setting.
- Processes that belong to root or another user need CCToolify Helper. You turn it on once in System Settings › General › Login Items & Extensions, and it only stops processes you pick.
The Ports guide walks through the whole screen. Read localhost vs 0.0.0.0 to learn what the “Who can connect” column tells you.