Port Already in Use
This operation is to free a selected port already in use. A simple alternative is to start your app on a different port but in this case we will see how to free up the port your app wants to use.
Quick reference
Section titled “Quick reference”sudo lsof -i :8000 # find process + PID on port 8000sudo ss -ltnp | grep 8000 # alternativesudo fuser 8000/tcp # one-shot: just print the PIDsudo fuser -k 8000/tcp # one-shot: find and kill in one step
kill <PID> # stop the processkill -9 <PID> # force-kill if it ignores killWhy sudo is needed
Section titled “Why sudo is needed”Running ss or lsof without sudo shows the port is occupied but hides the PID and process name. You need elevated privileges to see which process owns the socket.
sudo ss -ltnp | grep 8000sudo lsof -i :8000The output will show the process name (e.g. python, uvicorn, docker-proxy) and the PID.
Kill by PID
Section titled “Kill by PID”kill <PID>kill -9 <PID> # if the process ignores the first killOne-shot with fuser
Section titled “One-shot with fuser”fuser skips the find then kill two step run:
sudo fuser 8000/tcp # print PID onlysudo fuser -k 8000/tcp # kill it directly