How To Create a Jekyll Blog On Ubuntu Cloud Server

How to create a Jekyll blog on Ubuntu Cloud Server

If you want to go from a blank slate VPS or baremetal dedicated server to hosting a powerful but low-profile website, creating a Jekyll blog is a great option for you. Jekyll is a static site generator, which means it can generate a blog-style website with no database software required, and yet you get many of the same features you have come to expect from the most popular dynamic site generators like WordPress, Drupal, and Joomla.

Many users will install Jekyll locally and then upload the static files of the site to their server. This tutorial takes a different path, installing Jekyll on the server first and setting up all of the necessary configuration remotely. This gives you some attractive options:

  1. With this option, you can do all of your Jekyll work while logged in on the command line. Many users prefer to work on the command line because they find it faster.
  2. This installation procedure also leaves open the option of setting up your remote Jekyll site as a Git repo, which you can sync to your local workstation. This means you don’t have to manage multiple Ruby installations in different locations. You can edit your Jekyll files locally and then push them to the server via convenient Git commands. A simple post-receive hook can then build your site remotely.

If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.

check markCentOS, Debian, or Ubuntu check markNo Bloatware check markSSH and Root Access

Using Apache As The Web Server

By default, your cloud VPS already has the Apache web server installed and configured. So in order to complete this tutorial you will be using that existing configuration. However, if you wish to install a different web server you can turn Apache off and replace it with another service.

If you decide to use Apache as is, you will be using the default /var/www/html directory as the document root for the website you will be building with Jekyll. You will be installing Jekyll in your user home directory, but the static files used by the site will be built into the /var/www/html directory.

Create a Sudo User

Your cloud VPS gives you instant root user access to install software and attend to critical system maintenance. However, for operating and building your website you want to avoid using the root user. For the purposes of website creation you will want to create a dedicated “sudo” user.

Please refer to the full guide on how to create a sudo user in Ubuntu.

Prepare For Jekyll Installation

In order to run a Jekyll site you will need to make sure you have Ruby installed, as well as GCC, Make, and some additional utilities.

Install prerequisite software for your Ubuntu system recommended by the Jekyll documentation using the command below:

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

The Jekyll documentation also recommends not installing RubyGems packages as your root user. The following commands will build RubyGems support in your user’s home directory:

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

The first line merely creates a comment in your .bashrc file indicating what the following lines entail. The remaining lines update the GEM_HOME variable and add the “gems” directory to your $PATH variable. This means whenever you log into your server as the sudo user you created, your Bash scripts will run properly. You should be able to copy the entire block above and paste it into your terminal.

Now you should be able to go ahead and run the gem commands to install Jekyll:

gem install jekyll bundler

This process may take a few minutes.

You now have the Jekyll app installed. In the next series of steps you will create a new website with Jekyll and begin publishing content right away.

How to Create Your Jekyll Blog

The Jekyll documentation recommends using the Bundler application to manage the Ruby Jekyll app:

bundle init

This command will create a “Gemfile” in your home directory. You can use this file to set up project dependencies. In this case, you want to set Jekyll as a dependency. At this point your Gemfile may contain some boilerplate information:

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

To add Jekyll as a dependency, you can use any text editor to edit the file, but for the purposes of this demonstration the nano text editor will be sufficient:

nano Gemfile

Add gem "jekyll" on its own line.

Finally, it’s time to create a Jekyll site. For this example, we will create a site called “blog”. The following command will install the new Jekyll site in a directory called “blog”:

jekyll new blog

That’s it! Your Jekyll site is created. Before you start creating content, you can enter the “blog” directory to change the destination where your site will be built. Remember, you are going to be using the default document root configured in Apache, /var/www/html. To configure this setting, you must edit the _config.yml file and a line for “destination” as follows:

destination: /var/www/html

To see your site live, you just need to build it. But before the build process, you will need to erase the default Apache index file, since this file was created by root it will not be able to be overwritten by Ruby, so go ahead and remove it:

sudo rm /var/www/html/index.html

Now, proceed with building the default Jekyll site with this command:

bundle exec jekyll build

Now, like magic, visit your primary domain in a web browser and you will see a new Jekyll site with the default, mobile-responsive Jekyll theme.

The Jekyll default theme home page

Next Steps

This article provided you with a complete walk-through that takes you from a brand new cloud VPS server to a running Jekyll blog, but it did not cover an important step of installing a free SSL certificate. To learn how to do that you should check out our full guide on setting up a free Let’s Encrypt SSL using Certbot.

Also, you may be interested in using NGINX as your web server instead of Apache. Some users prefer NGINX for one reason or another: maybe they find the configuration syntax easier, or they like the way NGINX can be used as a reverse proxy. If you want to try out NGINX as an alternative to Apache, you can check out our full guide on NGINX basics for Debian systems. Even though the article is written for Debian, you should have no trouble adapting those steps for Ubuntu, since Ubuntu is based on Debian.

CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+