How to define Hugo version?

Hi,

How can I set a specific version of Hugo to Render ?

Setting the environment variable HUGO_VERSION has no effect.

1 Like

Hi Jess,

We don’t support multiple versions of hugo at the moment.

I’d love to learn more about your use case for pinning hugo’s version ? What version are you looking to use ?

Thank you for your response.

Testing multiple Hugo versions is often required to test issues with templates and websites based on Hugo.

1 Like

Does Render’s build environment use the latest version of Hugo always?

I haven’t tried it in a while, chiefly because of the lack of this capability; but, the last time I did, it wasn’t the most current.

Yeah not being able to specify a Hugo version is certainly a bummer. In contrast, Netlify allows a way to specify a version.

EDIT: Thinking about this a bit more. A potential workaround would be to deploy a Docker-based web service that simply serves the static files. It would be still be “fronted” with Render’s CDN. That should work.

Hey there,

So it’s true that we don’t have a slick way to control the version of Hugo - but, it’s actually entirely possible to use whichever version you like.

The Render buildCommand can be a script, as opposed to say, hugo --gc and if you were to have a render-build.sh script that did:

# save as render-build.sh and make sure it's executable
hugo version # Output the OLD version
if [[! -f $XDG_CACHE_HOME/hugo]]; then 
  echo "...Downloading HUGO" 
  mkdir -p ~/tmp 
  wget -P ~/tmp https://github.com/gohugoio/hugo/releases/download/v0.99.1/hugo_0.99.1_Linux-32bit.tar.gz 
  cd ~/tmp
  echo "...Extracting HUGO" 
  tar -xzvf hugo_0.99.1_Linux-32bit.tar.gz
  echo "...Moving HUGO"
  mv hugo $XDG_CACHE_HOME/hugo  
  cd $HOME/project/src # Make sure we return to where we were
else 
  echo "...Using HUGO from build cache"
fi

$XDG_CACHE_HOME/hugo version # Output the NEW version
$XDG_CACHE_HOME/hugo --gc --minify`

then you can control the version of Hugo that your site is built with :grin:

John B

2 Likes

@John_B that’s awesome! It would be nice to mention this in the docs. I am sure it’ll be useful for users who use other static site tools. What you suggested is way better (and simpler!) than the workaround I added in my comment.

I have a slightly updated version of what @John_B posted above. This works for me. However, I am not sure how long the build cache stays around. If it stays around until you manually clear build cache and trigger a manual deploy, then it’s likely that the Hugo version will be whatever was last installed. I think this is a great starting point, though.

#!/bin/bash

# In your Render dashboard, set the HUGO_VERSION env var for your static site. You'll get the same experience as, say, Netlify.

TAR_NAME="hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz"

hugo version # Output the OLD version
if [[ ! -f $XDG_CACHE_HOME/hugo ]]; then 
  echo "...Downloading HUGO" 
  mkdir -p ~/tmp 
  wget -P ~/tmp https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${TAR_NAME} 
  cd ~/tmp
  echo "...Extracting HUGO" 
  tar -xzvf ${TAR_NAME}
  echo "...Moving HUGO"
  mv hugo $XDG_CACHE_HOME/hugo  
  # Make sure we return to where we were.
  cd $HOME/project/src
else 
  echo "...Using HUGO from build cache"
fi

$XDG_CACHE_HOME/hugo version

# Render sets IS_PULL_REQUEST to true for PR previews.
if [ "${IS_PULL_REQUEST:-}" = "true" ]; then
    $XDG_CACHE_HOME/hugo --gc -e preview
else
    $XDG_CACHE_HOME/hugo --gc --minify
fi

You’re exactly right, the build cache sticks around until you ‘Deploy and Clear’ the build cache, but if you’re setting the environment variable with the version then it would seem like you’re making a conscious decision to change the version so you should remember to clear the build cache.

Another option would be to compare the version in the environment variable to the output of hugo version (making sure you’re using the version from the cache) and if it’s different update it to match the version in the environment variable and recache it. Then, aside from changing the environment variable, there’s no other interaction required.

John B

1 Like

This is exactly what I was thinking would be the next step. I didn’t have the time to do this myself. But I am happy with changing the version and manually clearing the cache for now. Thank you for all the help @John_B!

Also I think it would be good to add this info to the docs somewhere. One could customize the build environment this way and cache their build tools too. It’s sort of similar to what other CI services offer in their pipelines.

Another way — if you don’t mind using Node.js stuff :slight_smile: — is to use the hugo-installer package.