Hugo 入门指南:从安装到第一篇文章
接上篇,这篇写给想自己动手搭 Hugo 博客的同学。零基础友好,按步骤来就行。
安装 Hugo
Ubuntu / Debian
apt-get install hugo
macOS
brew install hugo
验证安装
hugo version
如果输出了版本号,说明装好了。
创建博客项目
hugo new site myblog
cd myblog
这个命令会创建一个这样的目录结构:
myblog/
├── archetypes/ # 文章模板
├── assets/ # 资源文件
├── content/ # 文章目录
├── data/ # 数据文件
├── hugo.toml # 配置文件
├── layouts/ # 模板文件
├── public/ # 生成的静态文件(发布用)
├── static/ # 静态资源(图片、文件等)
└── themes/ # 主题
安装主题
Hugo 官方主题市场:https://themes.gohugo.io/
以 PaperMod 为例:
cd themes
git clone https://github.com/adityatelange/hugo-PaperMod.git
克隆完后,在 hugo.toml 里指定主题:
theme = "hugo-PaperMod"
写第一篇文章
hugo new posts/hello-world.md
这会在 content/posts/hello-world.md 创建一个文件,带预置 front matter:
---
title: "Hello World"
date: 2026-04-13
draft: true
---
这里是文章正文,用 Markdown 写。
draft: true 表示草稿状态,本地预览能看到,但不会出现在正式网站。写完改成 draft: false 或者直接删掉这行。
本地预览
hugo server
然后打开 http://localhost:1313 就能看到效果了。Hugo 支持热重载,改完保存页面自动刷新。
生成静态文件
hugo
所有文件会输出到 public/ 目录,把这个目录丢到任何 Web 服务器上就能访问。
常用 front matter 字段
---
title: "文章标题"
date: 2026-04-13
description: "SEO 用的简短描述"
categories: ["分类"]
tags: ["标签1", "标签2"]
draft: false
---
title:文章标题date:发布日期description:在列表页显示的摘要,也用于 SEOcategories:分类,可以有多个tags:标签,可以有多个draft:草稿标记,发布前改成 false
目录结构约定
Hugo 对内容目录有默认约定,了解一下可以避免踩坑:
| 路径 | 说明 |
|---|---|
content/posts/ |
博客文章 |
content/about.md |
关于页面 |
content/search.md |
搜索页面(需要配合搜索功能) |
Hugo 会把 content/ 下的目录结构映射为 URL 路径。content/posts/hello.md → /posts/hello/。
下一步
- 绑定自定义域名
- 配置 HTTPS 证书
- 接入搜索功能(PageFind)
- GitHub Actions 自动部署
有问题欢迎留言。