1. 环境准备

在开始之前,需要先准备好环境:

  • 安装 Node.js(推荐 LTS 版本)
  • 安装 Git

安装完成后,检查版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
node -v
npm -v
git --version
````

## 2. 安装 Hexo

在你想存放博客的文件夹中执行:

```bash
npm install -g hexo-cli
hexo init myblog
cd myblog
npm install

然后启动本地服务:

1
hexo s

浏览器访问 http://localhost:4000,就能看到默认页面。

3. 更换 Butterfly 主题

进入博客目录 myblog,下载 Butterfly 主题:

1
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

修改 _config.yml 文件,把主题改成:

1
theme: butterfly

安装必要依赖:

1
npm install hexo-renderer-pug hexo-renderer-stylus --save

重启服务后,你就能看到漂亮的 Butterfly 界面啦。

4. 写文章

使用命令新建文章:

1
hexo new post "我的第一篇文章"

文章会生成在 source/_posts/ 目录下,你可以用 Markdown 来写内容。

5. 部署到 GitHub Pages

  1. 在 GitHub 创建一个仓库,命名为:你的用户名.github.io
  2. 安装部署插件:
1
npm install hexo-deployer-git --save
  1. 编辑 _config.yml,加入部署配置:
1
2
3
4
deploy:
type: git
repo: https://github.com/你的用户名/你的用户名.github.io.git
branch: main
  1. 执行命令部署:
1
2
3
hexo clean
hexo g
hexo d

部署完成后,访问 https://你的用户名.github.io 就能看到你的博客啦!

6. 常用命令

  • hexo new post "文章标题" :新建文章
  • hexo s :启动本地服务器
  • hexo g :生成静态文件
  • hexo d :部署到远程

总结

从零开始搭建博客其实并不难,主要流程就是:

👉 安装 Hexo → 使用 Butterfly 主题 → 写文章 → 部署上线

之后你还可以:

  • 美化主题(添加背景、切换字体、增加特效)
  • 配置评论系统(Waline、Gitalk、Twikoo 等)
  • 添加站点统计(不蒜子、百度统计、Google Analytics)

未来再继续折腾!🚀