Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jekyll 2.2.0 | Error: Address already in use - bind(2)

Tags:

jekyll

I am new to Jekyll blogging and trying to view blog locally on

http://localhost:4000

but failed.

➜ my-awesome-site > jekyll serve
Notice: for 10x faster LSI support, please install http://rb-gsl.rubyforge.org/
Configuration file: /home/Git/my-awesome-site/_config.yml
        Source: /home/Git/my-awesome-site
   Destination: /home/Git/my-awesome-site/_site
  Generating...
                done.
Configuration file: /home/Git/my-awesome-site/_config.yml
jekyll 2.2.0 | Error:  Address already in use - bind(2)

I tried

$ lsof -wni tcp:3000
$ lsof -wni tcp:4000

but both of them return nothing.

My Ruby version is:

➜ my-awesome-site > ruby --version
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]

What should I do next? I've re-installed jekyll already but the same problem remains.

like image 297
controlled Avatar asked Aug 06 '14 03:08

controlled


4 Answers

See the comments in http://jekyllrb.com/docs/usage/, should help you:

If you need to kill the server, you can kill -9 1234 where "1234" is the PID.

If you cannot find the PID, then do, ps aux | grep jekyll and kill the instance. Read more.

like image 138
Matifou Avatar answered Nov 18 '22 02:11

Matifou


Steps here fixed it for me. I had to append 'sudo' along with the commands.

$> sudo lsof -wni tcp:4000

It will give you information of process running on tcp port 4000 which also contains PID (Process ID). Now use command below to kill the process.

$> sudo kill -9 PID

Now you can execute jekyll serve command to start your site

like image 30
Muhammad Nabeel Arif Avatar answered Nov 18 '22 02:11

Muhammad Nabeel Arif


Try to see which process is using that port, kill it and run again or try running jekyll on different port.

like image 33
Tuan Anh Tran Avatar answered Nov 18 '22 04:11

Tuan Anh Tran


If @Matifou's answer here doesn't work, do the following instead:

The fix for anyone: run jekyll serve on an unused port:

Two ways:

  1. In your _config.yml file, specify a port other than 4000 like this, for example:
    port: 4001
    
  2. OR (my preferred choice), add --port 4001 to your jekyll serve command, like this, for example:
    bundle exec jekyll serve --livereload --port 4001
    

From: https://jekyllrb.com/docs/configuration/options/#serve-command-options

See my answer here: Is it possible to serve multiple Jekyll sites locally?

My particular problem: NoMachine is interfering:

When I run:

bundle exec jekyll serve --livereload --drafts --unpublished

I get these errors:

jekyll 3.9.0 | Error:  Address already in use - bind(2) for 127.0.0.1:4000
.
.
.
/usr/lib/ruby/2.7.0/socket.rb:201:in `bind': Address already in use - bind(2) for 127.0.0.1:4000 (Errno::EADDRINUSE)

ps aux | grep jekyll doesn't show any processes running except this grep command itself. So, that doesn't help.

sudo lsof -wni tcp:4000, however, shows a running nxd nx daemon process:

$ sudo lsof -wni tcp:4000
COMMAND    PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nxd     914803   nx    3u  IPv4 7606783      0t0  TCP *:4000 (LISTEN)
nxd     914803   nx    4u  IPv6 7599664      0t0  TCP *:4000 (LISTEN)

I discovered this is due to my NoMachine remote login server.

If running NoMachine, click on the NoMachine icon in the top-right of your task bar. Ex: this is on Ubuntu 20.04:

enter image description here

Then click on "Show server status" --> Ports, and you'll see that NoMachine is running nx on Port 4000, which is interfering:

enter image description here

So, use the fix above to serve jekyll on a different port, such as 4001 instead of 4000. I recommend leaving the NoMachine port settings as-is, on port 4000, because NoMachine says:

  • Automatic updates require that hosts with NoMachine client or server installed have access to the NoMachine update server on port 4000 and use the TCP protocol.

See also:

  1. Is it possible to serve multiple Jekyll sites locally?
    1. my answer
like image 2
Gabriel Staples Avatar answered Nov 18 '22 04:11

Gabriel Staples