Cloud from A to Z

Installing Jekyll

Overview

Teaching: 15 min
Exercises: 0 min
Questions
  • What software does Jekyll depend on?

  • What are Gems?

  • How is Jekyll installed?

Objectives
  • Install Jekyll’s dependencies.

  • Configure Ruby to install Gems in your home directory.

  • Install Jekyll and bundler Gems.

In the previous episode I mentioned a number of static website systems, the systems I mentioned generate static websites from content you provide and are referred to as static website generators. Generally the content you provided is in the form of a text file in some format. Different static website generators have different formats they know how to read and convert into static websites. In this workshop we are going to be using the static website generator Jekyll which reads plain text files written in the Markdown format. We will look at the syntax of Markdown files shortly, but first lets install Jekyll on our webserver and create our first Jekyll website.

Prerequisits

These are Ubuntu software packages which Jekyll needs to run.

$ sudo apt install ruby-full build-essential zlib1g-dev

This took about 5 minutes.

Configure Ruby to install gems to your home directory

Ruby has its own packaging system for distributing Ruby libraries or plug-ins. One of these packages is referred to as a Gem. It is advisable to install these Ruby Gems into your own personal directory space. This can be beneficial if other users on the VM wish to install conflicting versions of Gems.

Why would you want different versions of Gems?

If you want to customize your Jekyll site different themes and plugins can depend on different versions of Gems. By installing Gems into a folder in your home directory you will not interfere with other people’s Gems.

There is a special file in your home directory .bashrc which contains a list of commands that are run in your new shell just before you get your first command prompt. This file is used for setting special configuration options you might like to have set in your shell. We are going to edit this file and add two commands to set a setting to tell Ruby where to install Gems, and one to set a setting to tell our shell where to find new commands provided by these newly installed Gems. In our case we want to install the Gems into a directory gems in our home directory rather than a system directory owned by the root user. Lets edit our .bashrc file with nano.

Nano is a text editor you can use from within a shell. When you run the nano file_name command it will open up the specified file for editing. It will display the contents of the file in your shell and you can type in text to create the contents of the file. Along the bottom of the terminal screen nano lists commands you can run, like Exit, by pressing the Ctrl and X keys. The ctrl key is represented with the ^ character.

$ nano ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
.
.
.

There are many lines of commands in here that likely don’t make a lot of sense to you at this point, however, we don’t need to worry about them as we want to add a couple extra commands to the bottom of this file to configure where Ruby installs Gems and leave the rest of it untouched. Use the down arrow to scroll down to the bottom of the file and enter the following lines of text.

# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$HOME/gems/bin:$PATH"

The first line that we entered beginning with a # is a comment line. Meaning it isn’t a command we want executed when we login, but rather some text to tell us about what the following commands are for. The two lines following the comment beginning with an export are setting two variables that Ruby and our shell use to locate things. The first export line sets a setting telling Ruby where to install gems. In this case we want it in a gems directory in our home directory, $HOME. $HOME is replaced with the current users home directory, in our case it will be /home/ubuntu. The second export command is telling our shell where to look to find new commands provided by the gems we install. The PATH setting is a list of directories separated by a : that our shell should look in for commands we are trying to execute. In this case we are adding the $HOME/gems/bin directory to the beginning of the list so it will look in this directory first for any commands we try to execute and then all of the usually places already listed in the PATH setting. The $ character allows you to reference the current value of a setting, for example the $HOME setting value, or the $PATH setting value.

Now that we have those lines added, lets save and exit our editor. For those new settings to take effect without having to exit and ssh back into our VM we can use the source command, which will read through a file and run the commands listed in it.

$ source ~/.bashrc

Install Jekyll and Bundler gems

Jekyll is a Ruby Gem and can be installed with Ruby’s package manager. Bundler is another Gem which aids in installing gems required by Ruby projects. Often when installing new Jekyll themes and plugins it is easiest to use Bundler to install the required Gems for those themes and plugins.

$ gem install jekyll bundler

This took about 5.5 minutes.

Key Points