Build the book's site HTML locally

This section covers how to build the HTML for your book locally, instead ofusing GitHub Pages. This allows you to host the book's HTML anywhere you like.

In order to locally build your book's HTML with Jekyll, you'll take one of two approaches:

  • Install a copy of the Ruby language (which is a free open-source language, but can be a pain to install).
  • Use a container software (Docker or Singularity) along with a Docker image that we'veprepared for youfrom this Dockerfile.

We recommend installing Ruby with one of the supplied methods first, and if this fails,try installing with a container tool such as Docker.

If you wish to use GitHub's Jekyll builder then you can skipthis section, because GitHub will automatically build your book'sHTML with its own version of Jekyll. In this case, skip tothe GitHub Pages publishing guide.

Building your book with Ruby

The most straightforward way to build your book's HTML is to installRuby and Jekyll.

In this case, you'll need Ruby, an open-source programming language, to build your book'sHTML. You won't need to know how to program in Ruby, we'll just use some tools that utilizeRuby's libraries.

Installing Ruby

There are a few different methods for installing Ruby, and their ease will dependon the operating system that you're using (in general, *nix platforms are morestraightforward to use for installing Ruby).

In the following sections we'll cover a few ways to install Ruby, they are roughly orderedfrom most-straightforward to most-difficult. Once you've finished those steps,head to install ruby plugins and follow the directions.

Using the conda-forge recipe rb-github-pages

The easiest way to install Ruby on nix systems is to usethe conda* package manager. On some systems the following should work:

  1. conda install -c conda-forge rb-github-pages

This will install pre-compiled binaries for the Ruby package GitHub pages, Jekyll, and all of their dependencies. If this works for you, you can skip straight to the section using make install.

Using the official Jekyll instructions

The Jekyll Documentation provides their own set of instructionsfor how to install Ruby locally on your system. These are a bit more involved, but ingeneral should work for many operating systems. Here are a few links to OS-specificinstructions.

Using conda-forge to install Ruby from scratch

If you are on a platform for which the rb-github-pages package isn't available, you can also try install Ruby and a C++ compiler manually using conda, as follows:

  1. conda install -c conda-forge ruby

Once you have Ruby installed, the conda-built clang compiler for yoursystem needs to be installed. Details depend on your OS and are shown below.

Install clang compilers
On OSX

Two steps are needed on OSX. First, install the conda's clang compiler:

  1. conda install -c conda-forge clangxx_osx-64

If you are running OSX 10.14 (Mojave) you also need to install system libraries inthe default *nix locations by running

  1. open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
On Linux

Install conda's clang compiler:

  1. conda install -c conda-forge gxx_linux-64

Install Ruby plugins

Regardless of the approach used above, you'll next installthe Ruby plugins for your specificbook. To do so, change into your book's directory, and run

  1. make install

which will install the following things:

  • Bundler (a Ruby dependency management tool) if it is not already installed(e.g. by running conda install -c conda-forge rb-github-pages)
  • A collection of Jekyll plugins for your book

Build your book's HTML

Once you have Ruby installed, you can preview your book'ssite locally by running this command:

  1. make serve

This should run Jekyll, building your site, and then open up a port on your computer with a live version of the book.It will generate your book's HTML in the _site/ folder. This collection of files makes afunctioning static website.

If you'd like to only build your book's HTML without previewing the site, you cando this with the following command:

  1. bundle exec jekyll serve

Once the collection of HTML files is in _site/, you can move on topublishing your book online.

Building your book HTML with Containers

If the above steps do not work for you, then you can try building yourbook's HTML with containers.

Containers canprovide an easier installation for many systems.If you are developing on a system where you have administrator privileges(i.e., you have root permissions), we recommend you use Docker.

We also provide instructions for using Singularity,an alternate containerization software for systems where you do not have administrator privileges.To learn more about using containers, please see theDocker for scientists guide.

Docker

First, you'll need to make sure you have Docker installed.There are installation instructions for each operating systemto guide you through this process.

Once Docker is available on your system, you can build the image locally with:

  1. docker pull emdupre/jupyter-book

You can then access this image with the following command.Make sure to specify the full path to your Jupyter Book, rather than the relative path!

  1. docker run --rm --security-opt label:disable \
  2. -v /full/path/to/your/book:/srv/jekyll \
  3. -p 4000:4000 \
  4. -it -u 1000:1000 \
  5. emdupre/jupyter-book

If you navigate to http://0.0.0.0:4000/jupyter-book/ in your browser,you should see a preview copy of your book.If you instead see an error, please try to update your local book;see the Jupyter Book FAQ sectionfor more details on how to do so.

You'll find the HTML for your book in the _site/ folder.

Singularity

If you are on a system where you do not have administrator privileges (such as a sharedcomputing cluster), you will not be able to use Docker.Instead, you can use Singularity.First, you'll need to check with your resource manager that Singularity is availableon your system.

You can then create a Jupyter Book Singularity image using:

  1. singularity build jupyter-book.simg docker://emdupre/jupyter-book

Next, you can access this image with the following command.Make sure to specify the full path to your Jupyter Book, rather than the relative path!

  1. singularity run -B /full/path/to/your/book:/srv/jekyll \
  2. --pwd /srv/jekyll \
  3. jupyter-book.simg

And that's it! If you navigate to http://127.0.0.1:4000/jupyter-book/ in your browser,you should see a preview copy of your book.

Host your book online

Now that you've finished building the HTML for your book, it's time to host thecontent online. See one of the following pages for instructions on how to do this:

This page was created by The Jupyter Book Community