Eclectic ENFJ, sketcher, bioinformagician.
Gabriele Girelli's avatar

Installing Ruby on Ubuntu 22.04

Installing Ruby on Ubuntu 22.04

Almost exactly one year ago (:scream: time flies!) I posted a 6-step guide on how to start your own Jekyll static website (check out the link if interest).

Now, after failing to live up to my new year’s resolution of one blog post a month, I got back to the blog on a new computer, obviously running the latest stable Ubuntu OS version.

Very naively, I installed ruby with a simple sudo apt install ruby. This seemed to work great but, when I continued to install Jekyll with gem install bundler jekyll I got welcomed by an error message:

You don't have write permissions for the /var/lib/gems/... directory.

I googled a bit and found only two solutions. The first would be to give my account permission to write in that folder, which did not sit well with me, while the latter is to uninstall ruby and start from scratch…

Of course, I decided to go for the second one - no surprise there, right?! I ended up using rbenv to manage the whole installation, which boiled down to a few simple steps:

1. Install rbenv

I decided to install rbenv using brew.

# Install rbenv
brew install rbenv

# Initialize it and add it to your shell profile
rbenv init

# !!! NOTE: The following line depends on your shell, I use zsh
# The rbenv init should give you the proper text to append to your shell profile file
echo 'eval "$(rbenv init - zsh)"' | tee -a ~/.zshrc

# Close and re-open the shell

# Verify installation
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash

2. Install ruby

rbenv install  3.1.2

3. Install and start jekyll

gem install bundler jekyll

Then, to start Jekyll, first you need to install your gems again.

bundle install
bundle exec jekyll serve

And, lo-and-behold, I got an error!

'require': cannot load such file -- webrick (LoadError)

Apparently, some gem dependencies changed in Ruby 3+. This is easily fixed by adding the missing gem explicitly. I also found that that the issue was already reported in Jekyll’s official repository.

bundle add webrick
bundle exec jekyll serve

And that worked 🎉

📷 Cover picture by @joshuafuller, on Unsplash.com ❤️
Installing Ruby on Ubuntu 22.04
(Updated: )
Interact with this post on
Categories