🖥️ 本地环境详细准备步骤(Windows)
1. 系统要求检查
Windows 10 或更高版本
至少 8GB RAM(推荐 16GB)
至少 10GB 可用磁盘空间
2. 安装 PowerShell 7
方法一:Microsoft Store(推荐)
打开 Microsoft Store
搜索 “PowerShell”
选择 “PowerShell 7+”,点击安装
安装后,在开始菜单找到 PowerShell 7 并启动
方法二:手动安装
验证安装:
1 2 3 $PSVersionTable .PSVersion
3. 安装 Visual Studio Code
步骤:
下载 VSCode
安装 VSCode
安装必要扩展
打开 VSCode,按 Ctrl+Shift+X,搜索并安装:
Chinese (Simplified) Language Pack (中文语言包)
GitHub Theme (可选主题)
GitLens (Git 增强)
Hexo Utils (Hexo 工具)
Markdown All in One (Markdown 增强)
Prettier (代码格式化)
4. 安装 Git
步骤:
下载 Git
安装 Git(详细配置)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 安装选项: 1. 选择组件: ☑ Git Bash Here ☑ Git GUI Here ☑ Git LFS (Large File Support) ☑ Associate .git* configuration files with the default text editor ☑ Associate .sh files to be run with Bash 2. 选择默认编辑器: ▸ Use Visual Studio Code as Git's default editor 3. 调整 PATH 环境: ▸ Git from the command line and also from 3rd-party software 4. 选择 HTTPS 传输后端: ▸ Use the OpenSSL library 5. 配置行尾符号转换: ▸ Checkout Windows-style, commit Unix-style line endings 6. 配置终端模拟器: ▸ Use Windows' default console window 7. 其他选项: ☑ Enable file system caching ☑ Enable symbolic links
配置 Git 用户信息
1 2 3 4 git config --global user.name "你的GitHub用户名" git config --global user.email "你的GitHub邮箱" git config --global credential.helper store
验证安装
5. 安装 Node.js v24.13.0
方法一:使用 nvm-windows(推荐)
安装 nvm-windows
安装 Node.js 24.13.0
1 2 3 4 nvm install 24.13 .0 nvm use 24.13 .0 nvm on
验证安装
1 2 node --version npm --version
方法二:直接安装
下载安装包
安装 Node.js
1 2 3 4 5 6 7 安装选项: 1. 接受许可协议 2. 选择安装路径(默认:C:\Program Files\nodejs\) 3. 自定义安装,确保勾选: ☑ npm package manager ☑ Add to PATH ☑ Automatically install the necessary tools...
6. 配置 npm 和镜像源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 npm config list npm config set registry https://registry.npmmirror.com npm config set prefix "C:\Users\你的用户名\AppData\Roaming\npm" npm config set cache "C:\Users\你的用户名\AppData\Roaming\npm-cache" npm config get registry
7. 安装 Hexo CLI 8.1.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 npm install -g hexo-cli @8.1 .1 hexo --version cd ~/Documentshexo init myblog cd myblognpm install hexo clean hexo generate hexo server
8. 安装和配置 Butterfly 主题
1 2 3 4 5 6 7 8 9 10 11 12 13 cd myblognpm install hexo-theme-butterfly @latest cp node_modules/hexo-theme-butterfly /_config.yml _config.butterfly.ymlcode _config.yml
1 2 3 4 5 6 7 8 9 theme: butterfly permalink: :year/:month/:day/:title/ permalink_defaults: pretty_urls: trailing_index: false trailing_html: false
9. 创建 GitHub 仓库
登录 GitHub :https://github.com
创建新仓库
点击右上角 “+” → “New repository”
仓库名:your-blog-name
描述:可选
选择:Public(公开)
勾选:Add a README file
点击 “Create repository”
本地配置远程仓库
1 2 3 4 5 6 7 8 9 10 11 cd mybloggit init git remote add origin https://github.com/你的用户名/你的仓库名.git code .gitignore
1 2 3 4 5 6 7 8 9 # .gitignore 内容: .DS_Store Thumbs.db db.json *.log node_modules/ public/ .deploy*/ _multiconfig.yml
10. 创建 Hexo 部署配置
1 2 3 4 5 npm install hexo-deployer-git --save code _config.yml
1 2 3 4 5 6 deploy: type: git repo: https://github.com/你的用户名/你的仓库名.git branch: main message: "站点更新: {{ now('YYYY-MM-DD HH:mm:ss') }} "
11. 创建第一个博客文章
1 2 3 4 5 hexo new "我的第一篇博客" code source/_posts/我的第一篇博客.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # 示例文章内容 --- title: 我的第一篇博客 date: 2024-01-15 14:00:00 tags: - 博客 - Hexocategories: - 教程 --- ## 欢迎来到我的博客! 这是我的第一篇博客,使用 Hexo 和 Butterfly 主题构建。 <!-- more --> ## 功能特点 - 🚀 快速生成静态页面- 🎨 美观的 Butterfly 主题- 📱 响应式设计- 🔍 SEO 友好## 后续计划 1. 添加评论系统2. 配置统计工具3. 优化加载速度
12. 本地测试
1 2 3 4 5 6 7 8 9 10 hexo clean && hexo generate hexo server
13. 部署到 GitHub
1 2 3 4 5 6 7 8 9 10 11 12 git add . git commit -m "初始化Hexo博客" git push -u origin main hexo deploy
14. VSCode 配置优化
创建 .vscode/settings.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "editor.formatOnSave" : true , "editor.defaultFormatter" : "esbenp.prettier-vscode" , "files.associations" : { "*.yml" : "yaml" } , "editor.wordWrap" : "on" , "editor.fontSize" : 14 , "workbench.colorTheme" : "GitHub Dark" , "markdown.preview.fontSize" : 14 , "terminal.integrated.fontSize" : 13 , "git.autofetch" : true , "git.confirmSync" : false }
15. 创建快捷脚本
在博客根目录创建 deploy.ps1:
1 2 3 4 5 6 7 8 9 Write-Host "开始部署..." -ForegroundColor Greenhexo clean hexo generate hexo deploy git add . git commit -m "更新: $ (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" git push origin main Write-Host "部署完成!" -ForegroundColor Green
设置执行权限:
1 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
16. 验证完整环境
运行验证脚本:
1 2 3 4 5 6 7 8 9 10 @" 验证环境配置: 1. PowerShell 版本: $ ($PSVersionTable .PSVersion) 2. Git 版本: $ (git --version 2>$null ) 3. Node.js 版本: $ (node --version) 4. npm 版本: $ (npm --version) 5. Hexo 版本: $ (hexo --version | Select-Object -First 1) 6. VSCode 版本: $ (code --version 2>$null | Select-Object -First 1) "@ | Write-Host
🚀 故障排除
常见问题解决:
权限问题
1 2 3 4 npm cache clean --force npm install -g npm@latest
端口占用
1 2 3 4 netstat -ano | findstr :4000 taskkill /PID 进程号 /F
Hexo 命令找不到
1 2 3 4 5 npm uninstall -g hexo-cli npm install -g hexo-cli @8.1 .1 [Environment ]::SetEnvironmentVariable("Path" , $env:Path + ";C:\Users\你的用户名\AppData\Roaming\npm" , "User" )
Git 提交失败
1 2 3 git config --global --unset credential.helper git config --global credential.helper manager