johnnian / Blog

MyBlog
Mozilla Public License 2.0
208 stars 59 forks source link

CentOS 7 安装Gitbook #49

Open johnnian opened 6 years ago

johnnian commented 6 years ago

安装步骤

步骤1: 安装NodeJS

[root@75d336b8c2cf ~]# yum install -y gcc make gcc-c++ openssl-devel wget
[root@75d336b8c2cf ~]# wget https://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gz
[root@75d336b8c2cf ~]# tar -zxvf node-v8.9.4.tar.gz
[root@75d336b8c2cf ~]# cd node-v8.9.4.tar.gz
[root@75d336b8c2cf node-v8.9.4]# ./configure
[root@75d336b8c2cf node-v8.9.4]# make && make install
[root@75d336b8c2cf node-v8.9.4]# node -v
v8.9.4
[root@75d336b8c2cf node-v8.9.4]# npm

Usage: npm <command>

步骤2: 安装Gitbook

[root@75d336b8c2cf ~]# npm install -g gitbook
[root@75d336b8c2cf ~]# npm install -g gitbook-cli
[root@75d336b8c2cf test]# gitbook
  Usage: gitbook [options] [command]

至此,Gitbook 安装完成。

可以通过Gitbook官网,安装一些实用插件。

常用命令

➜  gitbook git:(master) ✗ gitbook --help

  Usage: gitbook [options] [command]

  Options:

    -v, --gitbook [version]  specify GitBook version to use
    -d, --debug              enable verbose error
    -V, --version            Display running versions of gitbook and gitbook-cli
    -h, --help               output usage information

  Commands:

    ls                        List versions installed locally
    current                   Display currently activated version
    ls-remote                 List remote versions available for install
    fetch [version]           Download and install a <version>
    alias [folder] [version]  Set an alias named <version> pointing to <folder>
    uninstall [version]       Uninstall a version
    update [tag]              Update to the latest version of GitBook
    help                      List commands for GitBook
    *                         run a command with a specific gitbook version

➜  gitbook git:(master) ✗ gitbook help
    build [book] [output]       build a book
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format                Format to build to (Default is website; Values are website, json, ebook)
        --[no-]timing           Print timing debug information (Default is false)

    serve [book] [output]       serve the book as a website for testing
        --port                  Port for server to listen on (Default is 4000)
        --lrport                Port for livereload server to listen on (Default is 35729)
        --[no-]watch            Enable file watcher and live reloading (Default is true)
        --[no-]live             Enable live reloading (Default is true)
        --[no-]open             Enable opening book in browser (Default is false)
        --browser               Specify browser for opening book (Default is )
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
        --format                Format to build to (Default is website; Values are website, json, ebook)

    install [book]              install all plugins dependencies
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    parse [book]                parse and print debug information about a book
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    init [book]                 setup and create files for chapters
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    pdf [book] [output]         build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    epub [book] [output]        build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

    mobi [book] [output]        build a book into an ebook file
        --log                   Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)

常见问题

1、Gitbook导出的HTML无法跳转

看了网上的介绍,可以安装下2.6.7版本解决这个问题, 具体步骤如下:

➜  gitbook git:(master) ✗ gitbook ls-remote
➜  gitbook git:(master) ✗ gitbook fetch 2.6.7
➜  gitbook git:(master) ✗ gitbook build --gitbook=2.6.7

2、报错:Cannot find module 'internal/fs'

这个是因为本机安装的NodeJS版本与NPM版本的问题,解决方法可以参考下面:

# 主要的思路是,安装正确版本的NodeJS和NPM
$ sudo n 6.9.1
$ sudo npm -g install npm@next
$ sudo n stable

参考链接