DEV Community

Cover image for Setting Up Jekyll, Resolving Webrick Issues, and Exploring Ruby Version Changes
TD!
TD!

Posted on

Setting Up Jekyll, Resolving Webrick Issues, and Exploring Ruby Version Changes

Day #21 of #100daysofMiva

As part of my ongoing #100DaysOfMiva coding challenge, Day 21 was all about getting familiar with Jekyll, a powerful static site generator built with Ruby. I encountered several configuration and dependency issues while setting up a Jekyll project, which led to valuable lessons in resolving them and understanding the technicalities behind Ruby version updates and gem dependencies.

In this report, I’ll walk through the entire process, from setting up the project to overcoming issues with deprecated gems in Ruby 3.0+, and how I addressed these challenges.

Setting Up Jekyll with Ruby 3.3.5

Jekyll is often the go-to tool for creating static websites like blogs and portfolios. It's fast, simple, and integrates well with GitHub Pages for easy hosting. The process for setting it up is fairly straightforward, but when working with newer versions of Ruby, there are a few additional steps required to address breaking changes in dependencies.

Initial Setup

To begin, I installed Jekyll and Bundler as global gems:

gem install jekyll bundler
Enter fullscreen mode Exit fullscreen mode

Then, I created a new Jekyll project:

jekyll new my_blog
cd my_blog
bundle install
Enter fullscreen mode Exit fullscreen mode

This creates the skeleton of a Jekyll site with directories like _posts, _layouts, and _includes. Running bundle exec jekyll serve should ideally launch the local development server and make the site accessible on localhost:4000. However, I encountered an issue immediately after running this command, especially because I was using Ruby 3.3.5.

The Problem: Webrick LoadError

After running bundle exec jekyll serve, I was greeted with the following error:

cannot load such file -- webrick (LoadError)
Enter fullscreen mode Exit fullscreen mode

This happens because, starting with Ruby 3.0.0, webrick (which Jekyll uses to serve your site locally) is no longer included as a default gem. This change was part of Ruby's efforts to slim down the default gemset, moving several libraries that were traditionally bundled into Ruby’s standard library into standalone gems.

The Fix: Adding Webrick to the Gemfile

To resolve this issue, I needed to manually add webrick to the project's dependencies by modifying the Gemfile in my Jekyll project.

  1. Open Gemfile in the project directory.
  2. Add the following line:
gem 'webrick'
Enter fullscreen mode Exit fullscreen mode
  1. Run the bundle install command to install webrick and update the project’s dependencies.
bundle install
Enter fullscreen mode Exit fullscreen mode

After this, the command bundle exec jekyll serve worked as expected, starting the local server on localhost:4000.

Exploring Ruby's Standard Library Changes

The experience with webrick also led me to discover that other standard library components like csv, bigdecimal, base64, and fiddle would also no longer be included by default in future versions of Ruby (e.g., Ruby 3.4.0 and beyond).

During the server startup, I encountered several warnings like these:

csv was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0. You can add csv to your Gemfile or gemspec to silence this warning.
Enter fullscreen mode Exit fullscreen mode

This led me to consider the importance of maintaining a clean and updated Gemfile to ensure that future versions of Ruby do not break my project by missing critical gems. Here’s an example of how to address the CSV warning by adding it to the Gemfile:

gem 'csv'
Enter fullscreen mode Exit fullscreen mode

Then, running bundle install again resolves the warning by explicitly managing the dependency.

Managing dependencies in Ruby projects is crucial, especially when working with tools like Jekyll that rely on specific gems for functionality. Here are some key takeaways from Day 21:

  1. Stay Current with Ruby Changes: Ruby is actively evolving, and understanding how changes in its default gemset affect your project is crucial. The removal of certain libraries from the default gems means that developers must take more responsibility for explicitly managing these dependencies.

  2. Gemfile Management: It's important to ensure that your Gemfile includes all necessary dependencies, especially as you upgrade to newer Ruby versions. This ensures your project is portable, maintainable, and future-proof.

  3. Incremental Debugging: When encountering errors like LoadError, it's tempting to try multiple fixes at once. However, incremental debugging (adding one gem at a time, rerunning the application, and checking for progress) is the best way to ensure that you correctly identify and fix the underlying issue.

Technical Details of the Fixes

Here’s a breakdown of the commands and steps used throughout the process:

Installing Jekyll and Bundler:

gem install jekyll bundler
Enter fullscreen mode Exit fullscreen mode

Creating a New Jekyll Site:

jekyll new my_blog
cd my_blog
bundle install
Enter fullscreen mode Exit fullscreen mode

Adding Webrick to the Gemfile:

In Gemfile:

gem 'webrick'
Enter fullscreen mode Exit fullscreen mode

Run:

bundle install
Enter fullscreen mode Exit fullscreen mode

Running Jekyll with Webrick Installed:

bundle exec jekyll serve
Enter fullscreen mode Exit fullscreen mode

Adding CSV Gem:

In Gemfile:

gem 'csv'
Enter fullscreen mode Exit fullscreen mode

Then, run:

bundle install
Enter fullscreen mode Exit fullscreen mode

Day 21 was a deep dive into resolving dependency issues while working with Jekyll and Ruby. The experience taught me to keep track of changes in the Ruby ecosystem, manage dependencies more carefully in my Gemfile, and deal with issues incrementally to isolate problems and apply targeted fixes.

You can follow my journey through the #100DaysOfMiva challenge on GitHub or connect with me on Dev.to to see all of my reports. Feel free to reach out if you have any questions or insights to share!

Top comments (0)