If youβre looking to build a static website or blog quickly, Jekyll could be a great solution. An open-source static-site generator written in Ruby, Jekyll allows for quick execution of commands that help manage your site from initial to production deployment, all from your command line. Jekyll is blog-aware, giving priority to categories, posts, and layouts with a range of importers available to import previous blog content. If you need to work offline often, prefer using lightweight editors to web forms for content maintenance, or wish to use version control to track changes to your website, Jekyll could provide you with what you need to accomplish your goals.
In this tutorial, we will install a Jekyll development site on Ubuntu 20.04 with automatically-generated content. With Jekyll installed, youβll be able to create a personal site or blog primarily using markdown files and a few Jekyll commands.
To follow this tutorial, you will need:
Once youβve completed this prerequisite, youβre ready to install Jekyll and its dependencies.
Weβll start by updating our package list to be sure we have the latest information on the newest versions of packages and their dependencies:
Next, letβs install make
and build-essential
so that Jekyllβs libraries will compile, and for Ruby and its development libraries to use. We include the y
flag here to confirm that yes, we would like to install the packages and avoid the prompt to confirm.
When thatβs complete, letβs add two lines to our .bashrc
file to tell Rubyβs gem
package manager to place gems in our userβs home folder. This avoids problems occurring from system-wide installations while also adding the local jekyll
command to the userβs PATH
.
Open .bashrc
with an editor of your choice, such as nano:
At the bottom of the file, add the following lines:
Save and close the file. To activate the exports, run the following:
When thatβs complete, weβll use gem
to install Jekyll itself as well as Bundler, which manages gem dependencies. Note that this may take some time.
Next, weβll make sure that our firewall settings allow traffic to and from Jekyllβs development web server.
Letβs check whether the firewall is enabled. If so, weβll ensure traffic to our site is permitted so we will be able to view our development site in a web browser.
If youβve encountered a status showing inactive
, run the following commands.
ufw allow OpenSSH
sudo ufw enable
This will enable your firewall to run on system startup. You may get the following prompts (confirm with βyβ to continue):
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
In our case, only SSH is allowed through:
OutputStatus: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
You may have other rules in place or no firewall rules at all depending on how you have set up your firewall. Since only SSH traffic is permitted in this case, weβll need to open port 4000, the default port for the Jekyll development server:
Now our firewall rules should include the following:
OutputTo Action From
-- ------ ----
OpenSSH ALLOW Anywhere
4000 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
4000 (v6) ALLOW Anywhere (v6)
Now with the software installed and the necessary port open, weβre ready to create the development site.
From our home directory, weβre using Jekyllβs new
command to create scaffolding for a site in a subdirectory called www
:
The jekyll new
command initiates a bundle install
to install the required dependencies, then automatically installs a theme called Minima. Following a successful installation, you should receive output like the following:
OutputNew jekyll site installed in /home/sammy/www.
Jekyllβs new
command creates the following directories and files:
...
βββ 404.html
βββ about.markdown
βββ _config.yml
βββ Gemfile
βββ Gemfile.lock
βββ index.markdown
βββ _posts
β βββ 2020-05-29-welcome-to-jekyll.markdown
βββ _site
These arenβt the actual web site files. They are the source files that Jekyll will use to create the static site. Jekyll relies on specific names, naming patterns, and directory structures to parse the different sources of content and assemble them into a static site. Itβs important to use the existing structure and follow Jekyllβs naming conventions when adding new posts and pages.
Tip: tree
is a useful command for inspecting file and directory structures from the command-line. You can install it with the following command:
To use it, cd
into the directory you want and type tree
or provide the path to the starting point with tree /home/sammy/www
Jekyllβs built-in lightweight web server is tailored to support site development by monitoring the files in the directory and automatically regenerating the static site any time a change is saved.
Because we are working on a remote server, weβll specify the host address in order to browse the site from our local machine. If you are working on a local machine, you can run jekyll serve
without the host setting and connect with http://localhost:4000
.
Output of jekyll serverConfiguration file: /home/sammy/www/_config.yml
Source: /home/sammy/www
Destination: /home/sammy/www/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.645 seconds.
Auto-regeneration: enabled for '/home/sammy/www'
Server address: http://203.0.113.0:4000/
Server running... press ctrl-c to stop.
When we invoked jekyll serve
, Jekyll parsed the configuration and content files into a new directory, _site
and started serving the content in that _site
folder:
...
βββ 404.html
βββ about.markdown
βββ _config.yml
βββ Gemfile
βββ Gemfile.lock
βββ index.markdown
βββ _posts
β βββ 2020-05-29-welcome-to-jekyll.markdown
βββ _site
βββ 404.html
βββ about
β βββ index.html
βββ assets
β βββ main.css
β β βββ main.css.map
β βββ minima-social-icons.svg
βββ feed.xml
βββ index.html
βββ jekyll
βββ update
βββ 2020
βββ 05
βββ 29
βββ welcome-to-jekyll.html
It also started watching the current directory, www
, for changes. As soon as a change to a post or page is saved, the static site will automatically be rebuilt, so itβs important not to make changes directly to files in the _site
folder.
If we leave this terminal open with the development server running in the foreground when working on our site, weβll receive immediate feedback as we add pages and posts and change content.
Note: If youβre working with a large site, enabling the --incremental
build can speed up the rebuild each time you make a change by only regenerating the files that are changed, but we donβt need it for this small site. You can learn more about this experimental feature on the Jekyll website.
The site is now available. In a web browser, we can visit it at the server address and port shown in the the output from jekyll serve
:
In this tutorial, we installed Jekyll and created a development site with some automatically-generated content. You can learn more about Jekyll by reading our other tutorials on the subject:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This comment has been deleted
Does this work for Debian? Since Ubuntu is based on Debian
Also, how do I use this with a domain name
Hello,
I am stuck at step 1 (.bashrc)
How to name this new file? Where should I save it?
Thanks in advance.