Clear port in use by another application

Fix "bind: address already in use" error by finding the process in use and stopping it.

Example error message:

$ my_command
2019/04/24 17:09:14 listen tcp bind: address already in use

Stop the process using port 3306:

$ sudo kill $(sudo lsof -t -i:3306)

Alternate method:

Clear the port, by finding the process using the port.

For example, find a process using port 8000.

$ netstat -tulpn | grep 8000

Running the netstat command will show an id on the far right. Stop the process by passing this process id to the kill command.

For example, if the id was 3746, run the following command.

$ kill 3746

1 comment

  1. anonymous

    Sometimes -9 is needed with the kill command:

    $ sudo kill -9 $(sudo lsof -t -i:3306)

Leave a Reply