HUGO, its Cache, and macOS

HUGO, its Cache, and macOS

Table of contents

No heading

No headings in the article.

My portfolio desperately needed a facelift. I considered different JS frameworks: Astro, Gatsby, and Next.js, but I wanted to work with a Go framework. I found a great one, and it’s called HUGO.

After reading its documentation and playing around with themes, I had it up and running in a matter of days. After pushing it to GitLab and deploying it on Netlify, something strange happened: my local server broke. HUGOs CLI wasn’t giving me an error, but going to http://localhost:1313 begot me: Page Not Found. Since I couldn’t see the changes, I blindly edited a page, pushed it to GitLab, and my deployed copy didn’t break. I was thoroughly confused.

I Googled my issue, and although I didn’t find a similar problem, I tried some suggested solutions—none worked. I checked HUGO's documentation and forum, and nobody seemed to have my problem. I posted my situation on the forum, and someone recommended I clone my repo, install it, and see what happens because my copy built without errors on their machine.

After cloning my repo and installing it…I got an error and I rejoiced!

go: github.com/jpanther/congo/v2@v2.5.2: reading github.com/jpanther/congo/go.mod at revision v2.5.2: git ls-remote -q origin in /var/folders/_9/sh0q476s25l2gs6wmvm4j49c0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/cache/vcs/066af87f3ece5bb7d6b6b53ce98f8b34566e9be8285986a3e33bbfe82661fac4: exit status 128:
    fatal: 'origin' does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
hugo: collected modules in 950 ms
Error: failed to download modules: failed to execute 'go [mod download]': failed to execute binary "go" with args [mod download]: go: github.com/jpanther/congo/v2@v2.5.2: reading github.com/jpanther/congo/go.mod at revision v2.5.2: git ls-remote -q origin in /var/folders/_9/sh0q476s25l2gs6wmvm4j49c0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/cache/vcs/066af87f3ece5bb7d6b6b53ce98f8b34566e9be8285986a3e33bbfe82661fac4: exit status 128:
    fatal: 'origin' does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
 *errors.errorString

I did two things: 1) post the error on the forum thread and 2) researched the error. The answer from both was the same: when HUGO first installs, it builds its cache directory on $TMPDIR/hugo_cache. Usually, this isn’t an issue, except on macOS…which OS am I running? macOS. The solution? Create a new cache directory for HUGO—one whose files won’t be deleted every time my computer has her beauty sleep—and configure the OS env.

Create a HUGO cache folder at the root directory: mkdir ~/.hugo-cache

Add an export line to your shell script, mine's .bashrc but by default it’s .zshrc on macOS:

export HUGO_CACHEDIR=~/.hugo-cache

…and now the local copy won’t break! WOOT!

Next up: creating my own HUGO theme. I’m thinking surrealism.