1. 安装git

2. 安装node.js

3. 安装cnpm

1
2
3
4
sudo su # 切换到root用户
npm -v # 查看node.js是否安装成功
npm install -g cnpm --registry=https://registry.npm.taobao.org #安装镜像
cnpm -v # 查看安装cnpm是否成功

4. 安装hexo

1
2
cnpm install -g hexo-cli # 安装hexo
hexo -v # 查看是否安装成功

5. 创建博客

1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir blog # 博客目录
cd blog # 切换到blog目录
sudo hexo init # 初始化博客
hexo s #启动博客,在浏览器输入localhost:4000
hexo n "My first blog" # 新建一篇博客文章
cd source/_posts/ # 切换目录
vim My-first-blog.md # 编辑博客
cd ../../ # 切换到blog目录
hexo clean # 清理
hexo g # 生成博客
hexo s # 启动
# 到目前为止,博客已经搭建完毕
# 下面将博客部署到github

6. 部署博客到github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 1. 登录github
# 2. 新建仓库
# 3. 在repository name输入你的github昵称 + github.io, 如"lupanlpb.github.io”
# 4. 在description输入介绍信息
# 5. 点击create
# 6. 安装git部署插件
cnpm install --save hexo-deployer-git # 安装过程会报出warning,可不予理会
# 7. 修改配置文件
vim _config.yml #
# 8. 在 Deployment处修改type、reporepo和branch如下
deploy:
type: git
repo: https://github.com/lupanlpb/lupanlpb.github.io.git
branch: master
# 保存退出
# 9. 部署到远端
hexo d # 部署,并根据提示输入github账号和密码

现在可以访问https://lupanlpb.github.io/了,这样博客就部署到github了!

7. 更换主题

  • 推荐使用Even
    1
    2
    3
    4
    5
    6
    git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia # 下载主题,在blog/themes目录下
    vim _config.yml # 修改配置文件将theme: landscape改为theme: even,保存退出
    hexo clean
    hexo g
    hexo s
    hexo d # 部署到远端