TCPServer Error: Address already in use - bind(2)

Solution 1:

Type this in your terminal to find out the PID of the process that's using the 3000 port:

$ lsof -wni tcp:3000

Then, use the number in the PID column to kill the process:

$ kill -9 PID

Solution 2:

I was not qualified to post comment. So I added a new answer.

I encountered this problem on Mac OS X 10.10.3. And I had never installed/used Jekyll before. I was not able to start jekyll server with its default port number 4000. The reason was that the port was the same as what NoMachine used. With

$ sudo lsof -wni tcp:4000

Note: Running this command without sudo will have no output.

I saw this output:

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nxd     449   nx    3u  IPv4 0x8d22************      0t0  TCP *:terabase (LISTEN)
nxd     449   nx    4u  IPv6 0x8d22************      0t0  TCP *:terabase (LISTEN)

The port 4000 was occupied by nxd, which was the process started by NoMachine. And

$ sudo kill -9 449

would not work, because NoMachine's nxd process would keep restarting, with a new PID.

Therefore, I had to either:

  • Changed my jekyll server port in the site _config.yml to another spared one. I appended the line below to _config.yml and it worked.

    port: 3000 # change server port to 3000

or

  • Changed NoMachine's default nxd port, or Uninstall NoMachine