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

4

19

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.

Crotch answered 6/8, 2014 at 3:24 Comment(0)
G
4

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

Gibran answered 12/8, 2014 at 10:3 Comment(3)
Could you please indicate how to run jekyll on a different port?Crotch
@Crotch in your _config.yml, add port: 4444 for example. Alternatively, you can do jekyll serve --watch --port 4444Gibran
Trying a different port helped me, as @TuanAnhTran saidDaloris
L
28

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.

Lothario answered 13/8, 2014 at 18:5 Comment(2)
➜ my-awesome-site > ps aux | grep jekyll username 53521 0.0 0.0 2432784 612 s000 S+ 2:12PM 0:00.00 grep jekyllCrotch
it seems that there is nothing to kill. The only running job that has keyword jekyll is "grep jekyll"Crotch
K
14

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

Kainite answered 6/9, 2016 at 14:32 Comment(0)
G
4

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

Gibran answered 12/8, 2014 at 10:3 Comment(3)
Could you please indicate how to run jekyll on a different port?Crotch
@Crotch in your _config.yml, add port: 4444 for example. Alternatively, you can do jekyll serve --watch --port 4444Gibran
Trying a different port helped me, as @TuanAnhTran saidDaloris
A
3

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
Aniela answered 30/12, 2020 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.