Hit the ground running with Ruby and Jekyll on MacOS
> Home
Edited 2019-01-09: Added notes about Debian compatibility.

When I initially tried to get Jekyll setup I ran into some issues with Ruby on MacOS, entirely unsurprisingly. While trying to resolve these issues I came across many resources on the internet that all provided partial solutions, but I don’t recall any one of them providing the entire solution I used. Unfortunately I did not document the resources I used to compile this, however my thanks go out to the many blogs, Stackoverflow posts and other various pages that led me in the right direction.

Previously I have tended to prefer to not use Homebrew to install packages as I have seen it create quite the mess on a machine that eventually had to be reimaged to get it back to a stable state. This installation will not use Brew, but installation via Brew is entirely possible and will likely save you a few commands.

A word of warning

But first, a word of warning, be cautious when copy and pasting commands from, well anywhere, but particularly the internet, as is demonstrated on Jann’s site on computer security [thejh.net]

Installation

Install rbenv

If Homebrew is installed, Brew will be used to install rbenv, however if Homebrew is not installed the script will checkout the git repository and compile from source.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash

Add the rbenv’s bin to the path, and make sure that it’s setup in the terminal.

echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

or for Debian

sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Start a new terminal session to activate so these changes are incorporated in the environment. Make sure the installation did what it was supposed to, this should report no issues.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Verify this now points to something along the lines of ~/.rbenv/shims/ruby

which ruby

Install a new version of Ruby

rbenv install 2.6.0

Grab a cup of coffee, this usually takes a few minutes.

rbenv global 2.6.0

Set rbenv to default to using the newly installed version and not the system version. This can be overridden on a per project basis by executing the command with local in the projects root directory:

rbenv local 2.6.1
rbenv versions

Confirm the active version is now set to 2.6.0

Bundler, Gems and Jekyll

gem install bundler

Install the Bundler gem.

bundler init

Create a new environment which will generate a new Gemfile which will need to be edited:

source 'https://rubygems.org' do
    gem 'jekyll

end
bundler install

Install the Gems from the Gemfile with Bundler.

All commands now need to be prefixed with bundler exec when operating within the Bundler environment, ie:

bundler exec jekyll serve

Concluding notes

rbenv, a new version of Ruby, Bundler and using Bundler, Jekyll are all installed and hopefully functional.