Linux安装nodejs和gitbook(CentOS 7.3)

一、Linux安装nodejs

    1、安装Node.js和NPM

     nodejs官网下载:https://nodejs.org/en/download/

Linux安装nodejs和gitbook(CentOS 7.3)_第1张图片   

    CentOS7.3系统是64位,所以下载了linux环境64位的安装包

    目前Node.js 的版本 :10.15.0

    npm 的版本: 6.4.1

    2、将 下载的安装包上传到服务器上(node-v10.15.0-linux-x64.tar.xz)

Linux安装nodejs和gitbook(CentOS 7.3)_第2张图片

   3、解压到自定义的文件下(/usr/local)

# 执行.xz的解压命令
tar xvJf node-v10.15.0-linux-x64.tar.xz -C /usr/local/

 Linux安装nodejs和gitbook(CentOS 7.3)_第3张图片

  4、配置换将变量

  执行命令:vim /etc/profile

   Linux安装nodejs和gitbook(CentOS 7.3)_第4张图片

# 在profile的最后边添加
#set for nodejs
export NODE_HOME=/usr/local/node-v10.15.0
export PATH=${JAVA_HOME}/bin:$PATH:${NODE_HOME}/bin
# 保存退出(:wq)执行命令是更改生效
source /etc/profile

  4、使用命令查看版本,出现相应版本号则表示成功

[root@ywlbuild local]# node -v
v10.15.0
[root@ywlbuild local]# npm -v
6.4.1

二、安装gitbook

   1、安装 gitbook-cli

# 执行命令
[root@ywlbuild ~]# npm install gitbook-cli -g
/usr/local/node-v10.15.0/bin/gitbook -> /usr/local/node-v10.15.0/lib/node_modules/gitbook-cli/bin/gitbook.js
+ [email protected]
added 578 packages from 672 contributors in 26.644s
[root@ywlbuild ~]#

  2、查看版本:gitbook -V  并安装GitBook   (注意:V大写)

   

Linux安装nodejs和gitbook(CentOS 7.3)_第5张图片

[root@ywlbuild ~]# gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3
[root@ywlbuild ~]# 

3、安装完成后,使用gitbook创建一个web站点示例

# 创建 web站点实例
[root@ywlbuild local]# mkdir /usr/local/gitbook

# 在gitbook文件夹下创建测试文件夹
[root@ywlbuild gitbook]# mkdir demo

# 切换到demo文件下
[root@ywlbuild gitbook]# cd demo

#初始化:gitbook (会生成README.md和SUMMARY.md两个文件)
[root@ywlbuild demo]# gitbook init
warn: no summary file in this book 
info: create README.md 
info: create SUMMARY.md 
info: initialization is finished 
[root@ywlbuild demo]# ls
README.md  SUMMARY.md


#生成web静态站点:gitbook build ./     
# (会生成_book目录,也就是静态站点,也就是编译好的html文件)
[root@ywlbuild demo]# gitbook build ./
info: 7 plugins are installed 
info: 6 explicitly listed 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 0.4s ! 

# 启动站点:gitbook serve ./ (默认地址:http://localhost:4000)
[root@ywlbuild demo]# gitbook serve ./
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed 
info: loading plugin "livereload"... OK 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 1 pages 
info: found 0 asset files 
info: >> generation finished with success in 0.5s ! 

Starting server ...
Serving book on http://localhost:4000

  浏览器访问(linuxip:4000)测试,gitbook部署成功Linux安装nodejs和gitbook(CentOS 7.3)_第6张图片

 

你可能感兴趣的:(NodeJs)