How to Install and Configure Hexo for a Static Blog on GitHub
This step‑by‑step guide shows how to install Hexo, set up Node.js and Git, configure a GitHub repository, customize themes and site settings, and publish a static blog using Hexo commands.
理想主义的功能不是卖钱,是它在实用主义无力的时候延伸了它的无言 ——严明
1. 安装 Hexo
什么是 Hexo?
Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内即可利用靓丽的主题生成静态网页。
安装前提
安装 Hexo 之前,需要系统中已有 Node.js 和 Git 环境。推荐使用 nvm 安装 Node.js。
使用 curl 安装 nvm:
curl https://raw.github.com/creationix/nvm/master/install.sh | sh使用 wget 安装 nvm:
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh安装完成后,重启终端并执行以下命令安装 Node.js:
nvm install stable安装并启动 Hexo
全局安装 Hexo CLI: npm install -g hexo-cli 如果没有 npm,可通过 yum 安装。
检查 Hexo 版本:
hexo -v初始化博客目录: hexo init blog 进入目录并安装依赖:
cd blog npm install生成静态文件并启动本地服务器:
hexo g hexo server默认在 4000 端口,可通过 -p <port> 修改。
在浏览器访问 http://localhost:4000/ 即可查看。
2. 在 GitHub 上的配置
添加公钥到 GitHub
生成 SSH 密钥:
ssh-keygen -t rsa -C "[email protected]"登录 GitHub,进入 Settings → SSH and GPG keys → New SSH key,粘贴公钥。
创建 GitHub 仓库
在 GitHub 个人页面点击 “Your repositories” → “New” 创建仓库,仓库名使用用户名。
修改配置文件
编辑博客根目录下的 _config.yml ,将 repository 地址改为新建的仓库 URL。
执行部署命令:
hexo generate hexo deploy若出现 ERROR Deployer not found: git ,安装 Git 部署插件:
npm install --save hexo-deployer-git完成安装查看博客
访问 https://wahaha5354.github.io/ 即可看到已发布的博客。
3. Hexo 博客配置
修改博客默认主题
从 Hexo 主题库 选择喜欢的主题,例如 next,克隆到本地:
git clone https://github.com/theme-next/hexo-theme-nextthemes/next编辑 _config.yml 将 theme: landscape 改为 theme: next 。
重新生成并部署:
hexo generate hexo deploy修改网站内容
编辑根目录下的 _config.yml ,修改以下字段: title: WangEr's Blog – 网站标题
subtitle: 生活不止眼前的苟且,还有远方的西洋参和鹿茸– 副标题
description: 记录生活的点滴,Linux 运维学习笔记– 网站描述(用于 SEO) author: wanger – 作者 language: zh-Hans – 语言 timezone: (默认使用电脑时区) – 时区
修改完成后执行:
hexo clean hexo g hexo d新建博文
使用以下命令创建新帖子或页面: hexo new [layout] <title> layout 可选,默认 post ,可在 _config.yml 中的 default_layout 更改。
布局(layout)
存储路径
说明
post
source/_posts
默认,可直接发布
page
source
在 source 下新建文件夹
draft
source/_drafts
草稿文件,写博客的草稿
示例:创建测试页并编辑内容: hexo new test 编辑 source/_posts/test.md 后再次执行:
hexo clean hexo g hexo d至此 Hexo 博客搭建完成,更多细节可参考官方文档 https://hexo.io/zh-cn/docs/ 。
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
