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.

controlled
  • 211
  • 1
  • 2
  • 6

4 Answers4

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.

Matifou
  • 7,968
  • 3
  • 47
  • 52
  • ➜ my-awesome-site > ps aux | grep jekyll username 53521 0.0 0.0 2432784 612 s000 S+ 2:12PM 0:00.00 grep jekyll – controlled Aug 13 '14 at 19:13
  • 1
    it seems that there is nothing to kill. The only running job that has keyword jekyll is "grep jekyll" – controlled Aug 13 '14 at 19:14
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

Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70
4

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

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
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
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265