Jekyll on Mac
Do it again
I recently posted a guide on how to use Jekyll as a static site generator on Windows. Time to do it again! This guide is for Mac.
Table of Contents
Requirements
- Github account (optional, but recommended)
- Computing device
- Base understanding of Git (here’s a refresher)
Brew
While Mac comes with Ruby, it’s usually a bit outdated from the latest. For instance, a June 2023 Mac ships with Ruby from April 2022. We don’t necessarily want to remove that version. For this reason, we will be installing Homebrew - a package manager. As of July 2023, paste this into Terminal: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
, or go to the website and look for the latest command.
Once it’s installed, you might want to consider adding it to your PATH variable to easily call it. As two separate commands, run (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/USER/.zprofile
(where USER is your Unix short name) and eval "$(/opt/homebrew/bin/brew shellenv)"
.
Ruby
Now that we have a nice package manager installed, let’s grab the Ruby version we need: brew install chruby ruby-install xz
.
Now, ruby-install ruby 3.1.3
(this will take a bit).
Configure Terminal to call chruby by default:
echo "source $(brew --prefix)/opt/chruby/share/chruby/chruby.sh" >> ~/.zshrc
echo "source $(brew --prefix)/opt/chruby/share/chruby/auto.sh" >> ~/.zshrc
echo "chruby ruby-3.1.3" >> ~/.zshrc # run 'chruby' to see actual version
Quit Terminal and re-open it. Run chruby
to make sure the above PATH updates worked and ruby -v
to check the right version of Ruby is now being used.
Jekyll
This is pretty straightforward. Type and run gem install jekyll
.
You are now at the point of cloning your existing website (if you have one) or making a new one. If you have an existing one, clone (see previous guide) and navigate to your site’s directory. Don’t forget to run bundle install
, or you will get some bad news:
To create a new site, navigate to the directory you want and type: jekyll new --skip-bundle . --force
.
Once you have a site generated or cloned, preview the website with bundle exec jekyll serve
or generate the HTML files with bundle exec jekyll build
.