The Port Conflict Problem
When you attempt to start a new web service on an Ubuntu Linux server, such as a local testing environment for Node.js or a fresh installation of Apache, the service will often instantly crash with a fatal error: “Address already in use: 0.0.0.0:80.” This simply means another program is already actively listening on port 80, preventing your new application from binding to it. To fix this, you cannot just delete files; you must identify exactly which background service is currently holding that port hostage and terminate its specific Process ID (PID).
Using the lsof Command
While you can use networking tools like netstat or ss to find this information, the “list open files” (lsof) command is much faster and more direct because Linux treats network sockets exactly like open files.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- Ensure the
lsofutility is installed by typingsudo apt install lsof. - To find the exact process using port 80, type the following command:
sudo lsof -i :80- Press Enter and provide your administrator password.
Understanding the Output and Killing the Process
The terminal will print a clear table. Look at the very first column (COMMAND) to see the name of the software (e.g., nginx or python3). The second column (PID) contains the critical numerical Process ID you need (e.g., 1452).
Once you have identified that the rogue process is an old, forgotten Python script running on PID 1452, you can terminate it instantly:
- Type
sudo kill -9 1452(replace 1452 with your actual PID). - Press Enter.
The -9 flag sends an absolute kill signal, instantly freeing the port so you can start your new web service without conflict.