Cyrus Yip's blog

Run Different Versions of Hugo without Installation via npx

Cyrus Yip
Table of Contents

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
 9
10
# local installed version or latest version
npx hugo-extended
# Hugo latest
npx hugo-extended@latest
# 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 --save-dev [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

To change the version, run install command again.

1
2
npm install --save-dev [email protected]
npm install --save-dev hugo-extended@latest # latest version

If you clone the repository, install 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

Note about package-lock.json #

By default, the directory name of source code will be shown in the name field in package-lock.json. To override that, set name field in package.json and run npm install.

Example of package.json:

1
2
3
4
5
6
{
  "name": "cyrusyip-blog",
  "devDependencies": {
    "hugo-extended": "^0.125.6"
  }
}

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

Tags:

Comments powered by giscus. If comments are not loaded, giscus may be blocked by your Internet service provider.