Building your Jekyll site locally

See the final result before publishing, without waiting for GitHub

Building your Jekyll site locally

Install Ruby and Jekyll to preview your documentation site on your machine, with automatic reloading at every change.

Duration :
Difficulty :

Software:

Machines/Tools:

Documentation completed: 60% 60
Created by:  Adrien Bracq

Why build locally

Editing from GitHub (previous tutorial) does not show the final result with the site’s real theme. Locally, jekyll serve rebuilds the site at every save and displays it in your browser within a few seconds: you see the result immediately, without publishing anything.

Installing Ruby 3.3 and Bundler

  Mind the version: Ruby 3.3.x

Install Ruby 3.3 (any 3.3.x version), not the latest version of Ruby. The template’s site uses the github-pages gem, which pins old versions of Jekyll; with Ruby 3.4 or later, bundle install or jekyll serve fail (for example cannot load such file -- csv). It is also the version GitHub uses to build your site (ruby-version: '3.3' in .github/workflows/ci.yml and pages.yml): same version locally and online, same result.

On the RubyInstaller download page, do not take the highlighted version: choose Ruby+Devkit 3.3.x (x64) in the list (the most recent 3.3 version).

During installation, keep the option that adds Ruby to the PATH ticked. At the end, leave the ridk install box ticked: a console opens and offers to install MSYS2 and the build toolchain; press Enter to accept the default choice. This Devkit is essential: on Windows, bundle install has to compile some gems.

Close and reopen the terminal, then check:

ruby -v
gem install bundler

ruby -v must display ruby 3.3.x.

With Homebrew, install version 3.3 explicitly (brew install ruby would install the latest version):

brew install ruby@3.3
echo 'export PATH="$(brew --prefix ruby@3.3)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
ruby -v
gem install bundler

ruby@3.3 does not replace the Ruby supplied with macOS: the line added to ~/.zshrc puts it first in the PATH. ruby -v must display ruby 3.3.x, and not ruby 2.6 (the macOS one).

Start by checking the version offered by your distribution:

apt-cache policy ruby

If the candidate version starts with 1:3.3 (this is the case with Ubuntu 26.04, for example), install it directly:

sudo apt update
sudo apt install ruby-full build-essential zlib1g-dev
gem install bundler

Otherwise (Ubuntu 24.04 and Debian 12 provide an older version, others a more recent one), install Ruby 3.3 with rbenv, which compiles Ruby in your home folder:

sudo apt update
sudo apt install git build-essential libssl-dev libyaml-dev zlib1g-dev libffi-dev libreadline-dev
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
source ~/.bashrc
rbenv install $(rbenv install -l | grep -E '^3\.3\.' | tail -1)
rbenv global $(rbenv versions --bare | grep -E '^3\.3\.' | tail -1)
gem install bundler

Compilation takes a few minutes. In all cases, ruby -v must display ruby 3.3.x.

  No administrator rights?

rbenv (Linux tab) installs Ruby in your home folder: only the installation of the build tools (apt install) requires sudo. If they are already present on the machine, you can skip that line.

Installing the project dependencies

bundle install

The site is in the docs/ folder of your repo, with its own Gemfile. In a terminal, go to that folder:

cd docs
bundle install

This installs all the gems needed (Jekyll, the theme, etc.), listed in the template’s docs/Gemfile file. All the commands in this tutorial are run from docs/, not from the root of the repo.

  Permission error on /var/lib/gems or /usr/lib/ruby

Without root rights, Bundler cannot write to the system gems folder. Configure it to install locally to the project instead:

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

The vendor/ folder is already ignored by Git (see .gitignore), so it does not clutter your repo.

Starting the local server

jekyll serve

Still from the docs/ folder:

bundle exec jekyll serve

Then open http://localhost:4000 in your browser. The site reloads automatically every time a file is modified and saved. Ctrl+C in the terminal stops the server.

Troubleshooting

Symptom Likely cause Solution
cannot load such file -- csv (or base64, bigdecimal…) when starting jekyll serve Ruby 3.4 or later: these libraries are no longer built in, and the pinned versions of Jekyll need them Install Ruby 3.3 (see above), check with ruby -v, then run bundle install again
ruby -v does not display 3.3.x although Ruby 3.3 is installed Another version of Ruby comes first in the PATH (macOS Ruby, system package on Linux) Reopen the terminal after editing ~/.zshrc or ~/.bashrc; which ruby shows which Ruby is used
On Windows, bundle install fails while compiling a gem (Failed to build gem native extension) The Devkit (MSYS2) is not installed Run ridk install in a terminal and accept the default choice, then run bundle install again
bundle: command not found although the installation seemed to succeed The bundler gem is installed in a folder missing from the PATH (frequent without root rights, a folder like ~/.local/share/gem/ruby/<version>/bin) Add this folder to the PATH: export PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin", then add this line to ~/.bashrc to make it permanent
bundle install fails with a permission error on a system folder No root rights to write to the shared gems folder See the box above: configure bundle config set --local path 'vendor/bundle'
One terminal sees neither ruby nor bundle although another terminal sees them The terminal used runs in non-interactive sh mode (does not load ~/.bashrc), or (on Linux with VSCode installed as a Flatpak) the integrated terminal runs in the Flatpak sandbox, isolated from the host system Try exec bash -l; if the problem persists with VSCode as a Flatpak, reinstall it as a native .deb/.rpm, or use flatpak-spawn --host bash -l
Could not locate Gemfile or bundle exec jekyll not found You are at the root of the repo, not in docs/ Run cd docs, then run the command again
The site builds but a page shows an error or does not display Error in the YAML front matter (indentation, missing quotes) Read the error message displayed in the terminal at build time; it generally names the file at fault

Exercise

Install Ruby and Bundler if you have not already done so, run bundle exec jekyll serve from the docs/ folder of your repo, and check that http://localhost:4000 does display your site with your latest changes.

Need help?