jekyll: Jekyll serve fails on Ruby 3.0

My Environment

Software Version(s)
Operating System Ubuntu 20.04
Ruby 3.0.0
jekyll 4.2.0
github-pages No

Expected Behaviour

bundle exec jekyll serve runs on Ruby 3.0.

Current Behavior

bundle exec jekyll serve fails with the following stack trace:

/home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `<top (required)>'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:179:in `require_relative'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:179:in `setup'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:100:in `process'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
	from /home/argilo/.gem/ruby/3.0.0/bin/jekyll:23:in `load'
	from /home/argilo/.gem/ruby/3.0.0/bin/jekyll:23:in `<top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:497:in `exec'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:49:in `block in <top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/friendly_errors.rb:130:in `with_friendly_errors'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:37:in `<top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/bin/bundle:23:in `load'
	from /home/argilo/.rubies/ruby-3.0.0/bin/bundle:23:in `<main>'

This happens because webrick is no longer a bundled gem in Ruby 3.0. From https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/:

The following libraries are no longer bundled gems or standard libraries. Install the corresponding gems to use these features.

  • sdbm
  • webrick
  • net-telnet
  • xmlrpc

Adding gem "webrick" to my Gemfile solves the problem, but Jekyll should include it in its gemspec.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 477
  • Comments: 82 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I think you want bundle add webrick.

Thank you @argilo, $bundle add webrick works!

+1 for the issue with webrick, I faced a similar problem when running jekyll serve in a different context than the one described here.

Thanks, adding webrick worked for me.

I have no idea what changed to require this.

It’s necessary because Jekyll depends on WEBrick, and WEBrick is no longer a bundled gem in Ruby 3.0: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

I fixed this by adding WEBrick to Jekyll’s gemspec in https://github.com/jekyll/jekyll/pull/8524, but it’s been almost a year and it has yet to be included in a Jekyll release. 😢 The workaround is to manually add webrick to your Gemfile.

Why is this issue closed? Dozens of comments in the lines of “fixed! works for me, thanks!” does not mean a problem is resolved.

My environment is a WSL2 Ubuntu LTS (meaning Ubuntu 22.04 running on Windows 10 or 11).

I used the bundler approach and I don’t use the root account, so my step by step was this:

$ sudo apt-get install ruby-full build-essential zlib1g-dev #this is the only time sudo should be needed
$ gem install --user-install bundler
$ mkdir user.github.io
$ cd user.github.io/
$ bundle init
$ bundle add jekyll

$GEM_HOME on a vanilla install is an empty string so this is mandatory, or bundler will invoke sudo:

$ bundle config set --local path 'vendor/bundle'

This command erased my existing Gemfile and .gitignore, I regret following the site’s instructions:

$ bundle exec jekyll new --force --skip-bundle .
$ bundle install
$ bundle exec jekyll serve

That last command will fail and lead me to one and a half hour learning about ruby, gems, bundler and ultimately to this issue.

There’s a missing step in the instructions somewhere before bundle install which is:

$ bundle add webrick

The default version in this particular environment is currently Jekyll 4.2.2 which does not include webrick in the jekyll.gemspec and therefore it doesn’t get added to Gemfile.

#8524 did not fix this issue so I don’t understand why it’s closed.

This issue will keep happening for everyone until they reach a version where this is fixed, which will take a lot of time.

The very least would be a document notice, but that has been proposed but not implemented.

Big thanks from me as well @argilo You’ve allowed me to stop working before midnight

I think you want bundle add webrick.

gigachad

Does adding the webrick gem definition to a Jekyll site’s Gemfile cause issues in ruby < 3.0?

No, it does not.

@argilo I have the same problem with Ruby 3.2.1 on macOS. Adding webrick to Gemfile doesn’t help. Jekyll 3.6.3. Upgrading to Jekyl 4.3.2 solved the problem.

That’s correct. The fix was merged into the master branch in January of 2021, but has yet to make it into any release.

This has been fixed, but do I understand correctly that the fix is not yet in any released version of Jekyll?

Pretty dope that this is still an issue.

I think you want bundle add webrick.

thanks,u save my day

Both bundle exec jekyll serve and jekyll s work for me ; despite, I’m getting a incompatible library version for http_parser.rb when appending the --livereload flag to the serve command, hence live reload is not active. Working with Ruby 3.0.0 in the MacBook Pro M1 with ARM64 processor. Here’s the log:

/Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http_parser.rb:2:in `require': incompatible library version - /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/ruby_http_parser.bundle (LoadError)
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http_parser.rb:2:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http/parser.rb:1:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http/parser.rb:1:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket/handshake.rb:1:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket/handshake.rb:1:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:15:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:15:in `block in <top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:14:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:14:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:3:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:3:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:143:in `require_relative'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:143:in `register_reload_hooks'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:98:in `process'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
        from /Users/xx/.rbenv/versions/3.0.0/bin/jekyll:23:in `load'
        from /Users/xx/.rbenv/versions/3.0.0/bin/jekyll:23:in `<main>'

Please note, as @persistz suggested, after

bundle add webrick

it is advisable to run

bundle update

to make sure other dependencies are updated to work with the new Ruby 3.0 version.