Developers
Port already in use on a Mac
Only one process can listen on a TCP port and address. A second server then stops with “address already in use”.
Symptoms
- A dev server stops with “EADDRINUSE” or “address already in use”.
- Docker cannot publish a port because “port is already allocated”.
- The port was free before a crash or a restart of your editor.
Likely causes
- An old copy of your server. A server from an earlier run still runs in the background.
- Another app. A different app uses the same port. On macOS 12 and later, AirPlay Receiver uses ports 5000 and 7000.
- A container. A running container publishes the same port on the Mac.
How to check
Find the process that listens on the port. Replace 3000 with your port.
lsof -nP -iTCP:3000 -sTCP:LISTENOutput The COMMAND and PID columns name the process.
To see processes of other users, run the same command with sudo.
sudo lsof -nP -iTCP:3000 -sTCP:LISTENNeeds an administrator password.
Show more about the process.
ps -p 12345 -o pid,commandLook for containers that publish the port.
docker ps
How to fix it
If the process is yours, stop it in its own Terminal window with Control-C.
Otherwise, send it the terminate signal. Use its PID.
kill 12345If it does not stop, use
kill -9. The process cannot save its data.If the process belongs to macOS, do not stop it. Choose another port for your server.
If the port is 5000 or 7000, read Port 5000 or 7000 is in use on a Mac: AirPlay Receiver.
With Kilobat
List the open sockets of one process.
kilobat destinations --pid 12345Quit a process by PID. Add
--forceonly if it does not stop.kilobat quit 12345
Questions
Why does lsof show nothing, but the port is in use?
lsof shows only the processes that you can examine. Run it with sudo to see all processes.
What do -n and -P do?
They stop lsof from converting addresses to names and ports to service names. The output is faster and shows numbers.
Sources
- lsof(8), man page installed with macOS 27.2
- kill(1) and ps(1), man page installed with macOS 27.2
- Apple Support: TCP and UDP ports used by Apple software products
Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.