Modules Overview

This article shows how to install, uninstall, upgrade, clean and tidy modules.

Initialize Modules and Themes

To use Hugo modules, you need to initialize your modules and themes first.

1hugo mod init example.com/user/blog

Install Modules

It’s quite simply to add a module into your site, just import the module path in configuration. Let’s take the example.com/user/module as an example.

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'example.com/user/module'

hugo.yaml

1module:
2  imports:
3  - path: example.com/user/module

hugo.json

1{
2   "module": {
3      "imports": [
4         {
5            "path": "example.com/user/module"
6         }
7      ]
8   }
9}

You’ll need to restart the Hugo server to load the module’s assets fully after installing modules.

Uninstall Modules

To uninstall modules, you need to remove or comment the modules from the configuration file, and then execute hugo mod tidy.

1[[module.import]]
2# path = "example.com/user/module"
1hugo mod tidy

Upgrade Modules

Upgrade all modules recursive:

1hugo mod get -u ./...

Update the latest version1 possible for a given module:

1hugo mod get -u example.com/user/module

Upgrade a specific version1:

1hugo mod get -u example.com/user/[email protected]

Tidy Modules

The following command remove unused modules from go.mod and go.sum.

1hugo mod tidy

Clean Modules Cache

Delete the Hugo Module cache for the current site:

1hugo mod clean

You may be interested in which modules the site imports and their dependencies.

1hugo mod graph
1hugo mod graph | grep blog

  1. The version can be any releases, tags, branches, or even commits. ↩︎ ↩︎

razonyang
Thursday, November 21, 2024 Saturday, February 4, 2023