This article shows how to install, uninstall, upgrade, clean and tidy modules.
To use Hugo modules, you need to initialize your modules and themes first.
1hugo mod init example.com/user/blog
example.com/user/blog
is the module path of modules and themes, which is usually the repository URL.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.
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 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/module@v1.0.0
The following command remove unused modules from go.mod
and go.sum
.
1hugo mod tidy
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