Getting Jekyll sites to generate on Ubuntu 20.04 in 2021
05 Jun 2021I’ve been having trouble getting a Jekyll-generated site to generate locally on Ubuntu 20.04, and after a few weeks of using my container instead, finally got it working. Thanks to folks on Twitter who gave me some clues!
Clue: error messages have a mix of user and system files.
The clue that got me started was that there was some error with Kramdown, which was at /usr/lib
. But it should have been installed in a user directory (/home/atabb
in my case). So an old version of Kramdown was being loaded from the system files, which clashed with newer version (or some other piece of ruby?) in the user files.
To fix this, I uninstalled the version of Ruby from the distribution and installed a newer Ruby using RVM, more on that ahead.
Start the fix, uninstall.
If you followed the typical way to get Jekyll installed from the Jekyll docs,
sudo apt-get install ruby-full build-essential zlib1g-dev
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
gem install jekyll bundler
Start undoing part of it.
Uninstall ruby-full
:
sudo apt remove ruby-full
delete the ~/gems
directory, and unset the path.
unset GEM_HOME
Start installing a new Ruby.
There’s lots of ways to get Ruby, I’ve used RVM before so that’s the approach I took.
First, go to the RVM page with the command-line instructions, grab the GPG key, then I did ‘For installing RVM with default Ruby and Rails in one command, run:’ one, with the --rails
flag.
This will fail because there’s a hard-coded path in there for mkdir
.
current directory: /home/atabb/.rvm/gems/ruby-3.0.0/gems/websocket-driver-0.7.4/ext/websocket-driver
make "DESTDIR=" install
make: /usr/bin/mkdir: Command not found
make: *** [Makefile:202: .sitearchdir.time] Error 127
I know, but this is free software so anyway, SO to the rescue and create a symbolic link
sudo ln -s /bin/mkdir /usr/bin/mkdir
Follow the instructions on doing source _dirname_
whatever. You can see where the gems are now,
$ echo $GEM_HOME
/home/atabb/.rvm/gems/ruby-3.0.0
At the time of this writing, ruby-3.0.0 is the latest stable build. I didn’t write this down, but I did check the version of ruby installed by the distribution and it was in the low 2s.
Test test.
At this point I think I did
gem install jekyll bundler
but I don’t remember.
The Jekyll quickstart guide gives some instructions for a minima site with a few command-line instructions, so it is a good test.
This will also fail.
/home/atabb/.rvm/gems/ruby-3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
At this point, what the heck? But this error message was easy to track down, from Github:
This happens because webrick is no longer a bundled gem in Ruby 3.0.
The fix is
bundle add webrick
NOW bundle exec jekyll serve
works for the minima example. Whew!
For my own site, I had to install a bunch of gems,
gem install jekyll-paginate jekyll-gist jekyll-sitemap jekyll-feed jekyll-redirect-from
But got it working.