Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not bind to 0.0.0.0:8080, it may be in use or require sudo

Tags:

swift

vapor

Sometimes I get this error when trying to run a Vapor application from Xcode. Reopening Xcode doesn't help, only restarting of system do. Is it a bug of the framework? What should I do to prevent this?

like image 484
Alexander Doloz Avatar asked Jul 13 '16 17:07

Alexander Doloz


2 Answers

If using sudo does not fix this message, it means something is already bound to this port. It could be an instance of Vapor that didn't close correctly.

To fix this, you need to kill the previous instance. The easiest way to do this is:

lsof -i tcp:8080

Where 8080 is the port you are trying to use. This outputs something like:

COMMAND    PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
com.apple 4679 tanner    8u  IPv4 0x890f6b0b31966939      0t0  TCP 

Then kill the process bound to that port using its PID.

kill -9 4679
like image 167
tanner0101 Avatar answered Nov 16 '22 19:11

tanner0101


While Tanner's answer should help in most cases, for me the kill command had no effect and no output. So I completely quitted & restarted terminal. When running lsof there were no processes found anymore, and issue was solved.

like image 27
Adam Bardon Avatar answered Nov 16 '22 19:11

Adam Bardon