To free up a port that is currently being used by a process on Ubuntu, you need to identify the process and then terminate it. Here's how you can do that:
Identify the process using the port: Use the
lsofornetstatcommand to find the process ID (PID) of the process using the port. For example, to check port 3000:sudo lsof -i :3000Or using
netstat:sudo netstat -tuln | grep :3000Find the PID: The output of
lsofwill look something like this:COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 12345 user 22u IPv4 123456 0t0 TCP *:3000 (LISTEN)Note the PID of the process (in this example,
12345).Kill the process: Use the
killcommand to terminate the process using its PID. For example:sudo kill -9 12345Replace
12345with the actual PID from the previous step. The-9option sends a SIGKILL signal, which forces the process to terminate immediately.
Alternative Method: Using fuser
You can also use the fuser command to find and kill the process using a specific port:
Find the PID with
fuser:sudo fuser -k 3000/tcpThis command finds the process using port 3000 and sends a SIGKILL signal to terminate it. The
-koption kills the process.
Summary
- Use
lsofornetstatto find the PID of the process using the port. - Terminate the process using the
killcommand with the PID. - Alternatively, use
fuserto find and kill the process in one step.
These methods will help you free up the port on your Ubuntu system.

