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 entirely 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.
To properly install Jekyll, the following software and packages are necessary.
$ sudo apt-get update $ sudo apt-get install ruby ruby-dev make gcc $ sudo gem install jekyll bundler $ sudo apt-get install nodejs
Go to the directory of your website containing the
$ bundle install
If some errors happen, try this before running the above command:
$ sudo gem update --system
Host Jekyll Site Locally
Go to the directory of the Jekyll site.
# url: https://leimao.github.io # Host Jekyll site on GitHub url: # Leave blank. Host Jekyll site locally on http://127.0.0.1:4000/ by default.
Start Jekyll server:
$ bundle exec jekyll serve
The following message will show if the server started successfully.
Configuration file: /home/marine/Workspace/leimao.github.io/_config.yml Source: /home/marine/Workspace/leimao.github.io Destination: /home/marine/Workspace/leimao.github.io/_site Generating... done. Auto-regeneration: enabled for '/home/marine/Workspace/leimao.github.io' Configuration file: /home/marine/Workspace/leimao.github.io/_config.yml Server address: http://127.0.0.1:4000/ Server running... press ctrl-c to stop.
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.
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.
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.
$ sudo bundle update jekyll
Ubuntu RubyGem 3.1.4 has a bug.
$ sudo gem update --system Updating rubygems-update Successfully installed rubygems-update-3.1.4 Parsing documentation for rubygems-update-3.1.4 Done installing documentation for rubygems-update after 0 seconds Parsing documentation for rubygems-update-3.1.4 Done installing documentation for rubygems-update after 0 seconds Installing RubyGems 3.1.4 Traceback (most recent call last): 5: from setup.rb:28:in `<main>' 4: from setup.rb:28:in `require' 3: from /var/lib/gems/2.7.0/gems/rubygems-update-3.1.4/lib/rubygems.rb:1424:in `<top (required)>' 2: from /var/lib/gems/2.7.0/gems/rubygems-update-3.1.4/lib/rubygems.rb:1424:in `require' 1: from /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:49:in `<top (required)>' /usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:50:in `<class:Specification>': undefined method `rubyforge_project=' for class `Gem::Specification' (NameError)
Currenly, we could use RubyGem 3.1.3 instead to get around.
$ sudo gem update --system 3.1.3