Installing Gitbook on OSX

A short description of the post.


Center for Environmental Studies


September 4, 2015

I am in various stages of writing technical texts using R/RStudio/knitr and have been looking for some methods that help in this process. My goals are to be able to:

  1. Maintain a single source tree that can produce the text (including graphics, statistical analyses, etc). easily
  2. Be able to produce high quality typesetting
  3. Be able to easily make epub
  4. Include both Code and output in the text.

I’ve just run across Gitbook and it looks like a good option, particularly with the help of the R package Rgitbook. Here is a bit of work that I had to do to get things going on my machine.

You will need to make sure you have XCode installed (get it from Apple) for all the building tools. If you’ve had previous versions of XCode on your machine, you may need to reset xcode-select as:

sudo xcode-select -s /Applications/
  1. Download Node.js from their site.
  2. In R, install devtools and then require(“devtools”) and install_github(“jbryer/Rgitbook”)
  3. Try to install it as per the instruction here. If this doesn’t help, what I had to do was:
    1. Try sudo npm install gitbook -g
    2. If this fails, you need to clean the npm cache and figure out what the problems were. Depending upon your error message you may need to:
      • Clean up any locks: sudo chown -R $(whoami) ~/.npm/_locks

      • Clean the cache

        sudo npm cache clean
    3. Then install sudo npm install gitbook-plugins -g and sudo npm install gitbook-cli -g and you should be good.
  4. You should be able to go to R and require(Rgitbook) and then checkForGitbook() and get normal feedback.

Now you have it installed, you should go see for how to use it. Good luck! It seems like this R package hasn’t been updated in a while. I hope it isn’t stale, it looks pretty interesting.