Setting Up Jekyll Site Locally
Introduction
Two years ago, I firstly learned Git, GitHub and built my first Jekyll site hosted on GitHub on Windows. However, because Jekyll does not support Windows without using a virtual machine, I had to upload new materials of my sites to GitHub and watch if the formatting and content were shown correctly on the site every time I wanted to update my site.
Since 2017, I have switched my working environment almost exclusively to Ubuntu, but I still have not got Jekyll installed on my computer and tested my site locally, which is pretty bad for a person who studies computer science. Today, somehow I get a chance to get Jekyll installed and successfully hosted my site locally, which I should have done two years ago. Here I documented the process and caveats for my future references.
Jekyll Installation
To properly install Jekyll, the following software and packages are necessary.
1 | $ sudo apt-get update |
Go to the directory of your website containing the Gemfile
file.
1 | $ bundle install |
If some errors happen, try this before running the above command:
1 | $ sudo gem update --system |
Host Jekyll Site Locally
Go to the directory of the Jekyll site.
In _config.yml
, leave url
blank.
1 | # url: # Host Jekyll site on GitHub |
Start Jekyll server:
1 | $ bundle exec jekyll serve |
The following message will show if the server started successfully.
1 | Configuration file: /home/marine/Workspace/leimao.github.io/_config.yml |
Now go to http://127.0.0.1:4000/
in a web browser to view the site.
Changing the localhost url is feasible. But I am not going to learn how to do it for now.
Inconsistencies
So far, everything looks OK except that the coding block does not show properly in the localhost. Someone has also reflected similar problems on GitHub. But I have not found a solution to solve this problem.
Issues
Since Ruby has been upgraded to 2.7, there might be a lot of deprecations warnings due to that Jekyll was not compatible with Ruby 2.7. Please upgrade Jekyll accordingly.
1 | $ sudo bundle update jekyll |
Ubuntu RubyGem 3.1.4 has a bug.
1 | $ sudo gem update --system |
Currently, we could use RubyGem 3.1.3 instead to get around.
1 | $ sudo gem update --system 3.1.3 |
Connection Reset Errors
When I start the sever locally and I connect the server from my browser, I always see this connection reset error message. Although it seems that it is not affecting the website at all, but it is annoying.
1 | $ bundle exec jekyll serve |
Later I found that if I enter http://localhost:4000
in the browser there will be no such error message. However, if I enter http://127.0.0.1:4000
in the browser the error happens. In addition, this error only happens in Chrome and Chromium, but not Firefox.
This error has bothered me for many years and I still have not come up with a good solution.
References
Setting Up Jekyll Site Locally