So you've built quite a portfolio in your career (so far), and you want to showcase yourself online. The first thing that would come to mind is to pay for hosting and pre-made website design for advertising your work.

Wouldn't it be even cooler to build your own site and have it hosted for free? The only other thing that's needed is some coding skills - which you probably already have, too!

In this article, you will learn how to setup create static websites using Jekyll, either from scratch or from a template. Also, publish that website to GitHub Pages - free of charge.

Getting Prepared

This article is a how-to guide, and the objective is that, in the end, you will have created your own static website hosted in GitHub Pages and Jekyll. To be able to follow along with this article, you must have the following requirements in place.

  • A Windows 10 computer with Windows Subsystem for Linux (WSL) enabled, and a Linux distribution installed such as the Debian GNU/Linux.
  • Linux is required because Jekyll is a Ruby Gem, and it needs Ruby to be installed. While Ruby can be installed on Windows, it is my experience that Ruby on Linux is a lot less problematic than when running it on Windows.
  • However, it is your choice to skip Windows and WSL altogether and just run everything on a Linux machine if you prefer. But, note that some of the instructions in this article may not be applicable.
  • In this article, a Windows 10 computer with Debian GNU/Linux distribution will be used.
If you want to learn how to enable WSL in Windows 10 and install Debian, you can go to the following links: Windows Subsystem for Linux Installation Guide for Windows 10Windows Subsystem for Linux (WSL): The Ultimate Guide
  • A code editor of your choice for editing your website. Like, Notepad++, Atom, and Visual Studio Code (recommended). In this article, Visual Studio Code will be used.
  • A GitHub account where your static website will be hosted. It is recommended to sign up for a new account for the purpose of testing.
  • A Git client such as GitHub Desktop which will be used in this article.

Installing Jekyll on Debian

Now that you have the necessary requirements, you can start installing the static site generator program - Jekyll. In this example, Jekyll will be installed inside the Debian Linux distribution inside WSL.

First, launch the Debian console. Then use the command below to make sure that the package list is updated.

sudo apt-get update

After running the command above, you should see a similar output, as shown in the image below. You need to wait for the update process to complete.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0946e2a4-2e24-447f-9cc3-18b711abd66d/Untitled.png
Updating Package Lists

Once the update is completed, use the command below to install all the required dependencies for Jekyll.

sudo apt-get install ruby-full build-essential

You might be asked to provide your consent to continue the install, similar to the prompt below. Agree to it to continue the installation.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6a2c2507-bb1e-4020-8997-e2edf93da920/Untitled.png

The installation may take several minutes depending on the speed of your system and internet connection. In this example, the installation took approximately 10 minutes to finish.

After completing the dependency installation, copy the command below and run it in your Debian console. The command below will add environment variables to avoid having to use sudo when using Ruby.

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

Lastly, use the command below to install Jekyll and Bundler. Copy the code and paste it to your Debian console window to run it. The installation may take another 5 to 10 minutes to complete.

gem install jekyll bundler

Once the installation is complete, you can confirm that Jekyll is successfully loaded by checking its version. To check the Jekyll version, use the command jekyll --version. As you can see from the screenshot below, the version installed on this development computer is jekyll 4.1.0.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4ec6d013-7239-4c4c-a4eb-fcfe6b1df80b/Untitled.png
Displaying the Jekyll version

Creating the GitHub Pages Repository

At this point, you would have already installed Jekyll. Before doing anything with it, you must first create the GitHub repository where your website will be hosted.

It was mentioned earlier in this article that you must have a GitHub account already available. It is also assumed that you have GitHub Desktop already installed and that you have logged in to it.

First, log in to GitHub Desktop using your GitHub account. Then, to create a new repository, click on File —> New repository.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/22c6b028-8a49-4ab8-8ccb-9ec949f17326/Untitled.png
New repository

In the New repository pop-up window, you need to provide the Name of the repository you are creating and the local path where the files will be stored.

The name of your repository must follow a specific naming convention. The name should be in this format - <username>.github.io - where <username> is your GitHub username. This naming convention must be strictly followed; otherwise, your website will not work.

In this example, the GitHub account name is jekylldev, so the resulting repository name is jekylldev.github.io. Once you've entered the repository name and the local path, click on the Create repository button.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2381e9ee-f1e7-479e-bcf5-153af30769ce/Untitled.png
Create the new repository

As you can see from the image below, an empty repository has been created in C:\GitHub\jekylldev.github.io.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/28f8fe4d-b4ed-43ff-b588-9b75e216e20d/Untitled.png
An empty repository is created

In the Debian Console, the path is obviously different. In this example, it can be found in /mnt/c/GitHub/jekylldev.github.io

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6131c86e-4b96-49ab-9902-4f7eab8530c2/Untitled.png

Back in the GitHub Desktop window, you should see a similar image like the one below. At this point, do not publish the repository yet.

You should see a button that says Open in Visual Studio Code, click on it.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/bf819091-6806-4ed3-9d2b-d6ef09fe9006/Untitled.png
Opening the repository in GitHub Desktop

The repository folder will be opened in Visual Studio Code, as shown in the image below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2b7c02c5-eeb0-42ce-b662-3696d702f0f4/Untitled.png
The new repository is opened in Visual Studio Code

Creating a Site from Scratch

In the previous section, you've opened your repository in Visual Studio Code. In this section, you will create a website from scratch, build the site, and test.

Adding the Homepage to Your Site

In Visual Studio Code, under the Explorer pane,  click on the New file icon. Then, name the new file as index.html.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4795d8ec-69cb-487c-a52d-08391ecacdde/Untitled.png
Create the index.html file

Then, copy the code below, paste it into your HTML file in VS Code, and then save it.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Sample Home Page</title>
  </head>
  <body>
    <h1>Hello, Welcome to JekyllDev</h1>
  </body>
</html>

The image below shows that index.html file is created, populated with code, and saved.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b5844b2b-7947-4d7e-93f7-1b87e12ae221/Untitled.png

Initializing Your Site

You've already created your home page file named index.html. But, before you can test it, you must initialize your website first.

To initialize your website, go to the Debian console and change the working directory to where your repository is stored. In this example, the path is /mnt/c/GitHub/jekylldev.github.io.

Next, use the command below to initialize the site and create a GemFile.

bundle init

After running the command above, you will get a similar output, as shown below. You'll notice that a new file has been created with the name GemFile.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ae05ebb8-f028-44de-9aba-2e32e1311c0b/Untitled.png
GemFile has been created

Next, go back to Visual Studio Code, click on the GemFile under the Explorer pane. The GemFile will be opened in the editor pane.

Go to the end of the file and append this code below. Then save the GemFile.

gem "jekyll"

The contents of the GemFile would look similar to the image below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c3150445-91c7-4ab0-8ad5-9ae611f64b9c/Untitled.png
Add jekyll as a dependency

After you've saved the GemFile, go back to the Debian console and run this command below.

bundle install

The command above installs the site's dependencies, and you should see a similar output like the screenshot below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/64f58856-f235-48c3-b765-4cc15352d946/Untitled.png

Building and Testing Your Site

Now that the site has been initialized, it is now ready to be built and tested. To build the website, go back to your Debian console and run this command below.

jekyll build

After running the code above, Jekyll builds the site and places the files under the _site folder in the repository. Assuming that the build was successful, you should see no errors, and the output would be similar to the screenshot below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e07bce27-a99c-4722-84ba-90f5f6b98575/Untitled.png
Successful Jekyll Site Build

Next, if you want to test or preview your site, run this command below instead.

jekyll serve

You will get an output similar to the one shown below. As you can see, there is a server address that you can use to view the site being served locally. In this example, the server address is http://127.0.0.1:4000

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0ad9798c-afa1-47a3-8682-ecc95e81fa24/Untitled.png

Using your browser, navigate to the specified server address to view your site.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/02875173-cf8a-435c-92f0-0672b1c3531c/Untitled.png
Testing the static website generated by Jekyll

To terminate Jekyll's serving of the site, go back to the Debian console and press CTRL+C.

Publishing Your Site

Your site has been built and tested. It is not yet published on the internet, and you can only access it locally on your machine. What's left for you to do is publish the GitHub repository that you have created, which will result in your published website.

To publish your repository, go back to GitHub Desktop and type a summary to the summary box. In this example, the summary is "initial commit" - this can be anything that you deem appropriate. After entering the summary, the description is optional. Then, click on the Commit to master button.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7384218e-406a-41f6-bc7a-38f5f6efcc8f/Untitled.png
Committing the initial changes to the repository

Next, after the commit has completed, you must click on the Publish repository button to publish the repository to GitHub.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e2e60f08-267b-4925-9144-ced0a12c985a/Untitled.png
Click on Publish repository

Next, you will be presented with the Publish repository pop-up window. You may add a description if you prefer. Make sure to uncheck the Keep this code private checkbox. Otherwise, your website will not be available to the public. Then, click on Publish repository.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/867ed831-988a-4102-ba27-4d246e61a02f/Untitled.png
Publish the repository

Once publishing is done, wait for at least two minutes, then use your browser and navigate to your newly published website. The URL would be the repository name itself. In this example, the website URL is https://*jekylldev.github.io*

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c1b199e1-37bd-4eea-b0c7-fc0d597de860/Untitled.png
The website is published online

Congratulations! You have now successfully published your first static website created in Jekyll GitHub Pages.

Creating a Site Using a Jekyll Theme

At this point, you have already created a sample website that contained nothing but the words "Hello, Welcome to JekylllDev". From there, you can opt to develop your own website design by following the Jekyll documentation.

Another option is to find an already existing Jekyll template (free or paid, the choice is up to you), and use that template as your site's base design. Many websites offer free Jekyll themes, and some are listed below.

As an example, you can use a Jekyll theme named Mediator to use as the base design of your website.

Before going any further, you first need to delete your repository in GitHub, delete the repository on your computer, and delete all the files associated with it. This is because you will be recreating your repository from another Jekyll template.

Using or applying a template to your Jekyll site may change depending on how the template owner designed it. The process that will be used in this article is a generic way of using a Jekyll theme.

Forking the Theme

Jekyll themes are typically hosted in GitHub as well. Simply go to the themes repository, in this example, the repository is at https://github.com/dirkfabisch/mediator.

From the theme's repository, click on the Fork button.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7815ee71-7150-447a-9947-4e37182b6d92/Untitled.png
Forking the theme's repository

Forking will create a copy of the repository into your GitHub account. Once the theme is forked, click on Settings.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3d538576-c29f-4605-9f37-2048702d9f88/Untitled.png
Open the repository settings page

Renaming the Repository

Inside the settings page, locate the Repository name box. You will see that the name is still the original name of the repository (mediator). You should change the name of the repository to <username>.github.io.

In this example, the repository name will be changed to jekylldev.github.io. Once you've typed in the name, click on the Rename button.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ecf3878f-b5e6-4a5e-b9ae-8c2fc294f5df/Untitled.png
Renaming the repository

After renaming the repository, go back to the Settings page and confirm that the site has been published in GitHub Pages by similar to the screenshot below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3d0519c4-ecab-4290-81d4-fb28c14ac952/Untitled.png
The site has been published

Then, when you click on the link or visit the address, you should see that it is already accessible, and the template has been applied.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/06cd63aa-fce6-480c-a5c2-982ddce681d0/Untitled.png
The website is accessible

Cloning the Website

You have successfully published a static website in GitHub pages with a beautiful Jekyll theme at this point. But, the contents of the website is still the same content from the original source.

Naturally, you will want to modify the contents of the website along with some of its components like the title, header, icon, banner photo, etc. Before you can do that, you will need to download or clone the website using GitHub Desktop.

To clone your website, open GitHub Desktop and click on Clone a repository. Then, you should be able to see the repository of your website from the list. Click on the repository and click Clone.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/79c0f838-552b-405c-9184-cba26d71571f/Untitled.png
Cloning your website repository

When you're prompted with "How are you planning to use this fork?", select For my own purposes, then click Continue.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5be05a35-a585-455e-8c28-1077277f5502/Untitled.png
Selecting the purpose of the forked repository

Once the repository is cloned to your computer, you can then open the repository in Visual Studio Code, where you can start modifying the code.

For example, change the site's title by editing the _config.yml file, as shown in the screenshot below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c103b8db-0892-4e3b-b35e-acf332d9727d/Untitled.png
Changing the title of the website

Testing the Changes to the Site

So you've modified the code of the site, and you want to test it. The way to test the changes to the website is similar to the process that was done when you tested the site created from scratch (refer to the Building and Testing Your Site section in this article).

If this is the first time you're testing the website after you've cloned it, you will need to first install the website's dependencies by running the command below in the Debian console.

bundle install

The above code will install the dependencies of the website. You must wait for it to complete as the installation may take several minutes.

Next, to test the site, run this command below.

bundle exec jekyll serve

Again, the server address to access the site locally is http://127.0.0.1:4000. And as you can see in the screenshot below, the title of the page has changed.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9cb5f708-86ba-4bbd-88e9-6c419eb7068f/Untitled.png
Confirming the changes made to the site

Once you're done testing the website, do not forget to stop the Jekyll server by pressing CTRL+C in the Debian console.

Pushing the Site Updates to GitHub Pages

When you're done and satisfied with the site changes to made and wanted to update your live website, you can do so by pushing the updates using GitHub Desktop.

From GitHub Desktop, type if the summary (required) and description (optional) of the changes made to the repository. Then, click on Commit to master.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/87808a0d-8e51-4b19-861e-82300fbd0959/Untitled.png
Commit the changes to the repository

Once the changes are committed, click on the Push origin button to push the site's updates to GitHub pages.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d211b813-2481-4953-ba99-001e64917df3/Untitled.png
Push the updates to GitHub Pages

Conclusion

In this article, you've learned how to create a static website using Jekyll and publish it in GitHub pages for free. You've also learned how to prepare your machine to install Jekyll and its dependencies.

You've also learned how to create a GitHub Pages repository by creating a new repository locally and publishing it to Github. As well as by forking an existing repository, renaming, cloning and republishing it using GitHub Desktop.

There's a lot more to Jekyll and GitHub pages than what can be covered in this article. Luckily, there is a lot of official and community documentation available. It is up to you to explore them and learn from them.

Further Reading