How to use Hexo blog
π Overview
- Install Hexo
- Initialize your blog project
- Build static pages locally
- Preview locally
- Configure GitHub repository
- Deploy to GitHub Pages
Install Prerequisites
Make sure you have:
1 | node -v |
If not, install them (Ubuntu example):
1 | sudo apt install nodejs npm git |
Node.js β₯ 16 is recommended.
Install Hexo
1 | npm install -g hexo-cli |
Initialize Your Blog
1 | hexo init my-blog |
Folder structure:
1 | my-blog/ |
Build & Preview Locally
Generate static pages
1 | hexo generate |
Run local preview server
1 | hexo server |
Then open:
http://localhost:4000
Deploy to GitHub Pages
Step 1: Create a new GitHub repo
Name it:
1 | yourname.github.io |
The repo name must match your GitHub username for Pages to work automatically.
Step 2: Install deployer plugin
1 | npm install hexo-deployer-git --save |
Step 3: Configure _config.yml
Add or modify at the bottom:
1 | deploy: |
Step 4: Build & deploy
1 | hexo clean |
This will:
- Clean old build
- Generate static files
- Push to your GitHub Pages repo
View Your Site
After a few minutes, visit:
https://yourname.github.io/
βοΈ Common Issues
| Problem | Cause | Fix |
|---|---|---|
fatal: could not read Username |
GitHub auth missing | Configure SSH or use a Personal Access Token |
Deployer not found: git |
Plugin missing | npm install hexo-deployer-git --save |
| Wrong branch | Wrong config | Change branch: in _config.yml |
| Blank page | Didnβt generate files | Run hexo g -d |
π§ Optional: Separate Source and Output Repos
You can keep:
- Source code in
hexo-source - Built site in
yourname.github.io
That keeps your main repo small and clean.
Quick Command Summary
| Task | Command |
|---|---|
| Initialize blog | hexo init my-blog |
| Generate pages | hexo g |
| Preview locally | hexo s |
| Clean cache | hexo clean |
| Deploy to GitHub | hexo d |
Would you like me to give you a ready-to-use deploy.sh shell script that automatically builds and pushes your Hexo site to GitHub in one command?
How to use Hexo blog