搭建hexo博客,快速简洁高效,零成本搭建个人博客:hexo

1. 环境准备

在搭建 Hexo 之前,需要确保你的电脑有以下环境:

1.1 安装 Node.js

Hexo 依赖 Node.js 运行环境,推荐安装 LTS 版本。

安装完成后,打开终端检查版本:

1
2
node -v
npm -v

如果显示版本号,说明安装成功。


1.2 安装 Git

Hexo 部署和版本管理需要 Git 支持。

安装完成后检查版本:

1
git --version

1.3 安装 Hexo CLI

通过 npm 安装 Hexo 命令行工具:

1
npm install -g hexo-cli

检查 Hexo 是否安装成功:

1
hexo -v

2. 初始化博客

在你想存放博客的目录执行以下命令:

1
2
3
hexo init my-blog
cd my-blog
npm install
  • hexo init my-blog:创建一个名为 my-blog 的博客目录
  • npm install:安装依赖包

3. 运行本地服务器

启动 Hexo 本地预览:

1
hexo server

浏览器打开 http://localhost:4000 即可查看博客首页。


4. 创建文章

Hexo 文章使用 Markdown 撰写:

1
hexo new post "我的第一篇博客"

文章会生成在 source/_posts 目录下,编辑完成后,可在本地预览:

1
2
3
hexo clean
hexo g
hexo s
  • hexo clean:清理缓存
  • hexo g:生成静态文件
  • hexo s:启动本地服务器

5. 选择主题

Hexo 支持丰富的主题,安装主题可以让博客更美观。

5.1 下载主题

常用主题推荐:

下载后,将主题放入 themes 文件夹,并在 _config.yml 中修改:

1
theme: next

重新生成博客:

1
2
3
hexo clean
hexo g
hexo s

6. 安装插件(可选)

常用 Hexo 插件:

  • hexo-deployer-git(用于部署到 GitHub Pages):
1
npm install hexo-deployer-git --save
  • hexo-generator-search(文章搜索插件):
1
npm install hexo-generator-search --save
  • hexo-tag-plugins(增强 Markdown 标签支持):
1
npm install hexo-tag-plugins --save

7. 部署到 GitHub Pages

7.1 创建 GitHub 仓库

  1. 登录 GitHub(https://github.com)
  2. 创建仓库,名称为 username.github.io

7.2 配置 Hexo

编辑 _config.yml

1
2
3
4
deploy:
type: git
repo: https://github.com/username/username.github.io.git
branch: main

7.3 部署命令

1
2
3
hexo clean
hexo g
hexo d

完成后,你的博客就可以通过 https://username.github.io 访问。


8. Hexo 常用命令汇总

命令 功能
hexo init [folder] 初始化博客
hexo new post “title” 新建文章
hexo clean 清理缓存
hexo g 生成静态文件
hexo s 本地预览
hexo d 部署博客

9. 参考资源


恭喜你!你已经成功搭建了属于自己的 Hexo 博客,可以开始写文章、分享知识、展示作品了。