Hugo 博客主题快速入门指南,涵盖环境安装、站点初始化、主题配置与本地服务启动。
安装 hugo
推荐安装 Hugo Extended(扩展版),以便完整支持 SASS/SCSS 编译与现代静态资源处理:
macOS (Homebrew)
brew install hugoLinux (Debian / Ubuntu)
sudo apt-get update
sudo apt-get install -y hugo或直接前往 Hugo GitHub Releases 下载最新的 .deb 安装包或预编译二进制压缩包解压使用。
Windows (Chocolatey / Scoop)
choco install hugo-extended
# 或
scoop install hugo-extended安装完成后,验证 Hugo 版本:
hugo version新建 site
在命令行中使用 hugo new site 命令快速初始化一个新的博客站点工程:
hugo new site myblog
cd myblog
git init目录结构包含 content/(文章内容)、layouts/(页面模板)、static/(静态资源)与 hugo.toml(配置文件)。
下载主题
将 hugo-bootstrap-x 主题引入到站点的 themes 目录下。推荐使用 Git Submodule(子模块)方式,便于未来随官方上游迭代更新:
# 方式一:推荐使用 Git Submodule
git submodule add https://github.com/xiexianbin/hugo-bootstrap-x.git themes/hugo-bootstrap-x
# 方式二:直接克隆到 themes 目录
git clone https://github.com/xiexianbin/hugo-bootstrap-x.git themes/hugo-bootstrap-x然后在站点的根配置文件 hugo.toml(或 config.toml)中指定启用主题:
theme = "hugo-bootstrap-x"启动
在站点根目录下运行 Hugo 本地调试服务器,并添加 -D 参数开启草稿(Draft)实时预览:
hugo server -D服务启动后,终端会输出本地访问链接(通常为 http://localhost:1313/)。打开浏览器即可实时预览博客效果,且支持文件修改自动刷新(LiveReload)。