π― The Goal
If youβre using GitHub Pages for your blogs, your site is likely powered by Jekyll. While pushing changes directly to GitHub works, itβs slow and riskyβyou donβt want to commit blindly and hope everything renders correctly.
The goal is simple: Run your Jekyll-based GitHub Pages site locally so you can preview changes instantly before deploying.
π§ The Workflow
Running a Jekyll-based GitHub Pages site locally is pretty straightforward once you set up the environment.
1. Install prerequisites
Youβll need:
- Ruby (Jekyll runs on it)
- RubyGems
- Bundler
On macOS/Linux, Ruby is often preinstalled. On Windows, you may need something like RubyInstaller.
Pitfall - 1
The system might still be using macOSβs default Ruby 2.6. Ruby 2.6 is deprecated and no longer supported by Jekyll or modern Ruby gems.
Solution
We need a newer version of Ruby (like 3.2+).
On macOS, the best way is to use Homebrew: Install a modern Ruby using Homebrew and rbenv:
brew install rbenv ruby-build
(Make sure to follow any instructions rbenv gives you about adding it to your shell configuration).
rbenv install 3.2.2
rbenv global 3.2.2
Pitfall - 2
gem install bundler jekyll
> ERROR: While executing gem ... (Gem::FilePermissionError)
> You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
It installs gems into a protected directory:
/Library/Ruby/Gems/2.6.0
Solution
-
Verify which Ruby is active
Run:
which ruby ruby -vIf you see something like:
/usr/bin/rubythen rbenv isnβt hooked into your shell.
-
Initialize rbenv properly
Add this to your shell config:
If you use zsh (default on macOS):
echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrcThen reload:
source ~/.zshrc -
Set and rehash Ruby
rbenv global 3.2.2 rbenv rehashCheck again:
ruby -v which rubyNow it should point to something like:
~/.rbenv/shims/ruby
2. Install Jekyll and Bundler
Run:
gem install jekyll bundler
3. Go to your project folder
cd your-github-io-repo
4. Install dependencies
If your project has a Gemfile (most GitHub Pages sites do):
bundle install
5. Match GitHub Pages environment (important)
GitHub Pages uses a specific setup. To avoid βworks locally but not on GitHubβ issues, use:
bundle add github-pages --group jekyll_plugins
This ensures your site uses the same versions and plugins as GitHub Pages.
6. Run the local server
bundle exec jekyll serve
Jekyll automatically rebuilds when files change. If not, try:
bundle exec jekyll serve --livereload
Then open your browser at:
http://localhost:4000
Other Common pitfalls
- Missing dependencies β run
bundle install - Port already in use β try
--port 4001 - Changes not showing β clear cache:
bundle exec jekyll clean