gitbook离线安装
calibre
# 编译安装
wget https://download.calibre-ebook.com/5.42.0/calibre-5.42.0-x86_64.txz
tar -xvf /tmp/calibre-5.42.0-x86_64.txz -C /opt/calibre/
ln -s /opt/calibre/calibre /usr/bin/calibre
ln -s /opt/calibre/ebook-convert /usr/bin/ebook-convert
Python3
glibc-2.18 (centos7使用)
tar -xvf glibc-2.18.tar.gz
$ cd glibc-2.18
$ mkdir build && cd build && ../configure --prefix=/usr && make -j4 && make install
Nodejs
# 下载v10.24.1版本,其他版本可能有问题
cd /tmp
wget https://nodejs.org/download/release/v10.24.1/node-v10.24.1-linux-x64.tar.xz
tar -xvf /tmp/node-v10.24.1-linux-x64.tar.xz -C /usr/local/
ln -s /usr/local/node-v10.24.1-linux-x64/bin/node /usr/bin/node
ln -s /usr/local/node-v10.24.1-linux-x64/bin/npm /usr/bin/npm
dependences
# sudo apt-get install gcc g++ make
Yarn
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
gitbook
npm install gitbook-cli -g
ln -s /usr/local/node-v10.24.1-linux-x64/lib/node_modules/gitbook-cli/bin/gitbook.js /usr/bin/gitbook
gitbook -V
使用
mkdir tbook
cd tbook
gitbook init
gitbook serve --port=4000
gitbook mobi .
ebook-convert book.mobi book.pdf
# 可能发生如下报错
Error: ENOSPC: System limit for number of file watchers reached, watch '/root/tmpbook'
# 扩大限制
sysctl fs.inotify.max_user_watches=524288
# 转换
gitbook pdf . ./mybook.pdf
# 可能发生如下报错:
[16889:16889:0925/062927.007936:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
# 是svgexport 调用了puppeteer调用了chromium然后产生的问题,使用下面语句绕过了:
export QTWEBENGINE_DISABLE_SANDBOX=1
常用命令
# init
gitbook init
# 启动服务预览
gitbook serve --port 4000
# 生成pdf\mobi\转换
gitbook pdf . ./mybook.pdf
gitbook mobi . mybook.mobi
ebook-convert mybook.mobi mybook.pdf
离线打包目录
除了下载的node-v10.24.1-linux-x64.tar.xz、calibre-5.42.0-x86_64.txz外,还需要打包gitbook和npm相关内容:
/root/.npm
/root/.gitbook
/usr/local/node-v10.24.1-linux-x64/lib/node_modules/gitbook-cli