Hexo博客搭建教程

本文最后更新于 2025年12月5日 凌晨

Hexo 博客搭建教程

💡 一、环境准备

1. 安装 Node.js

Hexo 依赖 Node.js 运行,请先完成安装。

前往官网下载安装完成后,打开命令提示符(CMD)验证:

1
node -v

若能返回版本号,则代表安装成功。

进行 npm 换源

1
npm config set registry https://registry.npmmirror.com

无报错表示换源完成。


2. 安装 Git

前往官网下载 Git,安装时使用默认项。

验证安装:

1
git --version

3. 安装 Hexo

在系统中打开 Git Bash,运行:

1
npm install -g hexo-cli

验证是否安装成功:

1
hexo -v

4. GitHub 部署准备

注册 GitHub 后,创建仓库:

<用户名>.github.io

建议设为私密库(后续涉及 API Key)。

配置 Git 全局信息(Git Bash):

1
2
git config --global user.name <你的用户名>
git config --global user.email <你的邮箱>

检查配置:

1
git config -l

5. 连接 GitHub(SSH)

生成 SSH 密钥:

1
ssh-keygen -t rsa -C <你的邮箱>

一路回车即可生成。

前往:

C:\Users\<你的用户名>\.ssh\id_rsa.pub
使用记事本打开,复制全部内容。

GitHub 添加密钥路径:

右上角头像 → Settings → SSH and GPG keys → New SSH key

测试连接:

1
ssh -T git@github.com

若出现连接成功提示,则环境部署完成。


💡 二、新建 Hexo 项目

在桌面或任意路径右键选择 Open Git Bash here,运行:

1
2
3
hexo init <项目名>
cd <项目名>
npm i

💡 三、配置 Hexo

推荐使用 Visual Studio Code 进行项目编辑。

运行开发环境:

1
2
3
hexo cl
hexo g
hexo s

浏览器访问:

http://localhost:4000/

按 CTRL+C 可停止运行。


💡 四、安装主题

推荐主题:Butterfly

请按照主题官方文档进行安装与配置。


💡 五、托管到 GitHub Pages

安装部署组件:

1
npm install hexo-deployer-git --save

修改 _config.yml 中的 deploy:

1
2
3
4
deploy:
type: git
repository: git@github.com:<用户名>/<用户名>.github.io.git
branch: main

部署到 GitHub:

1
2
3
hexo cl
hexo g
hexo d

出现 Deploy done 表示成功。


💡 六、部署到 Vercel

使用 GitHub 登录 Vercel:

Add New → Project → Import GitHub 仓库 → Deploy

完成部署后,在 Project → Domains
添加自定义域名,并在域名服务商中解析即可。


📚 总结

完成以上步骤后,你的 Hexo 博客已经成功搭建,实现:

  • 环境配置\
  • Hexo 框架搭建\
  • GitHub Pages 部署\
  • 主题美化\
  • Vercel 部署与域名绑定

Hexo博客搭建教程
https://hyper001.cn/posts/101.html
作者
Hyper001
发布于
2025年12月2日
许可协议