hexo+GitHub Pages搭建个人博客完整教程

hexo+GitHub Pages搭建个人博客完整教程

1.环境准备

1.1 安装Node.js

  • 官网下载:Node.Js 选择LTS版本
  • 验证安装:
bash 复制代码
node -V #查看Node.js版本(需>=14)
npm -V  #查看npm版本
node -V && npm -V
  • 注意:国内建议换到淘宝镜像源
bash 复制代码
npm config set registry https://registry.npmmirror.com

1.2 安装Git

  • 官网下载:Git
  • 验证安装
bash 复制代码
git --version

1.3 安装Hexo

bash 复制代码
npm install -g hexo-cli

2.项目搭建

1.1 新建文件夹

  • 比如在我的D盘创建hexo/blogtest文件夹

1.1 初始化项目

1. 初始化项目
复制代码
hexo init
  • 初始化成功后你可以在我们本地blogtest文件下看到如下文件
2.安装项目依赖(在当前博客目录 )

如果不在当前博客目录,切换一下就好了,拿我的举例子例,如 cd ./hexo/blogtest

复制代码
hexo install
  • 安装成功如下:
4.本地预览
复制代码
hexo clean && hexo g && hexo s

访问 http://localhost:4000

3.关联GitHub Pages

1.创建仓库
  • 仓库名必须为:<用户名>.github.io(如 coderyihong.github.io
  • 勾选 Add a README file
2.配置部署
  • 安装Git部署插件

    npm install hexo-deployer-git --save

  • 修改 _config.yml

ts 复制代码
deploy:
  type: git
  //建议使用SSH协议  某些平台(如 GitHub)对 HTTPS 请求有严格的速率限制(尤其未登录时)。
  //SSH 连接不受此限制,如果不会切换可以按照下面步骤走
  repo: git@github.com:coderyihong/coderyihong.github.io.git
  branch: master
2.1.切换SSH协议
1. 生成 SSH 密钥
bash 复制代码
ssh-keygen -t ed25519 -C "your_email@example.com"

(默认保存在 ~/.ssh/id_ed25519.pub

2. 将公钥添加到 Git 平台
  • GitHub: Settings → SSH and GPG keys
  • GitLab: Preferences → SSH Keys
  • Gitee: 设置 → SSH 公钥
3. 修改 Hexo 配置
yaml 复制代码
deploy:  type: git 
repo: git@github.com:你的用户名/仓库名.git  # SSH 地址格式  
branch: gh-pages
4. 测试连接
bash 复制代码
ssh -T git@github.com

看到 Hi 用户名! You've successfully authenticated 即表示成功。

3. 首次部署
bash 复制代码
hexo clean && hexo deploy -g

等待1-2分钟后访问 https://coderyihong.github.io

相关推荐
fthux7 小时前
装闭 RenoPit 源码解析(09):AnalysisEngine装修闭坑分析主流程
人工智能·ai·开源·github·open source·renopit
JackieDYH7 小时前
Git 与 GitHub 新电脑配置指南(从零开始)
git·github·工具·使用教程
云空17 小时前
《VPython 相关的 GitHub 仓库地址清单》
github·可视化·vpython
小弥儿20 小时前
GitHub今日热榜 | 2026-08-14:OSINT情报工具回流,本地AI赛道升温
人工智能·学习·开源·github
Shell运维手记1 天前
Linux 常用基础命令学习笔记
linux·运维·笔记·学习·算法·github
码流怪侠1 天前
StereoCrafter 源码级深度拆解:腾讯如何把 2D 视频“抠“成 3D
github·音视频开发·webvr
fthux2 天前
不必下载整个仓库:GitZip Pro 让 GitHub 文件与文件夹批量下载更简单
前端·chrome·ai·edge·开源·github·firefox
人工智能研究所2 天前
GitHub 10k+ Star:用自然语言描述系统,AI 帮你生成可交互架构图
人工智能·github·交互·自然语言·系统架构图·archify
逛逛GitHub2 天前
一个 Skill.md 拿下 1.8 万星,这个 GitHub 项目让 AI 先说重点。
github
云空2 天前
《GitHub 从入门到进阶完整教程》
github