npx lets you run different versions of Hugo without installation. To use it, install Node.js and npm at first.

Run different versions

The syntax of npx is npx <package-name>@<version>. If @<version> is not specified, the locally installed version or latest version will be used. Here are some examples:

1
2
3
4
5
6
7
8
# local installed version or latest version
npx hugo-extended
# Hugo v0.121.0
npx [email protected]
npx [email protected] version
npx [email protected] server
# Hugo v0.99.1
npx [email protected] version

Available versions are listed here. Oldest version is 0.63.2. If you want to use the older versions, use hugo-bin package instead. Its version doesn’t match the Hugo version, so you have to check its commit history.

1
2
# Hugo v0.121.0
npx [email protected] version

Install a specific version

You can install a specific version of Hugo in a git repository.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cd cyrusyip-blog
# install Hugo v0.99.1
npm install [email protected]
# ignore local npm packages
echo 'node_modules' >> .gitignore
# commit change
git add --all
git commit --message 'add Hugo'
# use
npx hugo version # Hugo v0.99.1

If you clone the repository, install the Hugo before using it.

1
2
3
4
git clone --recursive https://github.com/CyrusYip/cyrusyip-blog.git
cd cyrusyip-blog
npm install
npx hugo version # Hugo v0.99.1

Clean cache

1
2
3
4
# clean npx cache
npx clear-npx-cache
# clean npm cache
npm cache clean --force

This tutorial was tested with npm/npx v10.2.4 and Node.js v21.2.0 on Arch Linux.