Run Jekyll Static Content Website on Raspberry Pi

11 Dec 2021 by Simon Greaves

Overview

I run this static content website on Jekyll from files that are stored on GitHub.

To edit posts or add new content I would normally run a dev copy of the site locally on my laptop with Jekyll installed and modify it with Visual Studio Code then upload the changes to the live site on GitHub using git command line tools.
This works well except for those times I am not sat in front of my laptop, like now where I am sat on my iPad writing this. I wanted a solution where it could be hosted at home somewhere and then access it from mulitple locations and devices. My first thought was a VM (obviously, I am a VMware nerd after all!). This is ok if you don’t mind running a server 24/7 to host the VM, but I wanted something less power (and money) hungry, like my Raspberry Pi I use to run my home network tools, which uses a tiny amount of power and runs exceptionally quitely.

There are a few different blog posts out there with guidance on how to do this, but I wasn’t able to easily find one that was recent and with information that worked for my deployment. My Pi is a Raspberry Pi 4 with a default out of the box Raspberry Pi OS GUI installed, and a bunch of other software like Office applications, Scratch, browser and a few others. It also includes some of the prerequiste software like Ruby, however my version of Ruby didn’t work with the guides, and when I updated to a new version I ran into challenges as well, so this is what I did to successfully install and run my static site on Jekyll and then publish to GitHub, for your enjoyment!

First things first, check your version and if you are on an old version, we will update it to v3.x a bit later on.
ruby --version
Find out where its installed.
which ruby
Check you have gem, gcc, g++ and make installed. These are required to run Jekyll.

gem -v  
gcc -v  
g++ -v  
make -v  

Make a directory to store your static content website.
mkdir website
Go into the directory.
cd website/
Prepare your bashrc variables for the upcoming installs.

echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc  

Reload bashrc
source ~/.bashrc

Prepare the website directory with your existing static content site by cloning the remote public site to your local website directory.
git clone https://github.com/USERNAME/blog
Initialize the local repository.
git init
Add the remote origin copy, which in my instance is in my master fork on GitHub.
git remote add origin https://github.com/USERNAME/blog
Verify its set correctly.
git status
Pull the origin copy, just to make sure you have a synchronous copy of what’s on GitHub.
git pull origin master
Verify status again.
git status

Now’s the time to update Ruby to v3.x.
Add the script to install the latest Ruby instance.
wget https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh
Run the install script (This takes a little while to install).
bash install_ruby_rpi.sh
Reload the bashrc.
source ~/.bashrc
Verify the installed Ruby version, checking its now updated.
which ruby
ruby --version
Install bundler using Gem
gem install bundler
Install Jekyll
bundle install
If the install fails, update it first then install.
Update the bundle
bundle update
bundle install
Finally serve the Jekyll site. Note: If you want to access it from a remote session, like an iPad or Phone browser, specify the --host IP_ADDPRESS variable at the end.
bundle exec jekyll serve --host 192.168.2.61

Now you have the site up and running you can use the Git command line tools to upload updated content.

git status
git add -A
git status
git commit -m "New Comments on why updated or added"
git status
git push origin master
git status

Comments are closed for this post.