hugo 是推荐的静态网站生成器,mac 上可通过 brew install hugo 一键安装,支持极速构建、无运行时依赖,并可配合主题与本地服务快速预览。
直接用 homebrew 安装静态网站生成器非常简单,关键是选对工具、配好环境、避免常见卡点。主流静态网站生成器如 hugo、jekyll、hexo 都支持 brew 一键安装,无需手动下载或配置 path(homebrew 会自动处理)。
确认 Homebrew 已就绪
先确保 Homebrew 正常工作:
- 终端输入
brew -v,能看到版本号(如Homebrew 4.3.x)说明已安装成功 - 运行
brew doctor,提示Your system is ready to brew.表示环境干净 - 若提示
command not found: brew,请检查是否漏掉 shell 初始化步骤(尤其是 Apple Silicon Mac:需确认~/.zprofile中有eval "$(/opt/homebrew/bin/brew shellenv)")
安装常用静态网站生成器
根据需求选择其一即可,命令均为一行执行:
-
Hugo(Go 编写,极速、无依赖):
brew install hugo -
Jekyll(Ruby 生态,GitHub Pages 原生支持):
brew install jekyll(自动连带安装 Ruby 和 Bundler) -
Hexo(Node.js 生态,插件丰富):
brew install node && npm install -g hexo-cli(注意:Hexo 本身是 npm 包,但 Node.js 可用 brew 安装)
安装完成后,直接在终端输入 hugo version、jekyll --version 或 hexo -v 验证是否可用。
初始化并运行本地站点
以 Hugo 为例(最快上手):
- 新建项目:
hugo new site myblog - 进入目录:
cd myblog - 添加主题(如 PaperMod):
git init && git submodule add https://github.com/adityatelange/hugo-PaperMod themes/PaperMod - 启用主题并启动服务:
hugo server -D→ 浏览器打开http://localhost:1313即可实时预览
Jekyll 和 Hexo 同理,分别用 jekyll new myblog && cd myblog && bundle exec jekyll serve 或 hexo init myblog && cd myblog && npm install && hexo server。
提速与避坑提醒
国内用户务必提前配置国内镜像源,否则 brew update 和 brew install 可能超时或失败:
- 替换主仓库源(清华镜像):
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git - 替换核心公式源:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git - 替换 Cask 源(若需装 GUI 工具辅助开发):
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git - 执行
brew update刷新索引后,再安装生成器,速度提升明显











