Alpine Linux - Install Hugo from a Prebuilt Binary

You can install the extended edition of Hugo from the Alpine Linux package repository as described here: https://gohugo.io/installation/linux/#alpine-linux

However, like other Linux distributions, the Alpine Linux package repository may not contain the latest version.

To install a specific version of the extended edition of Hugo from a prebuilt binary:

#!/usr/bin/env sh

HUGO_VERSION=0.121.1
TEMP=$(mktemp -d)
wget -O "${TEMP}/hugo.tar.gz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
doas tar -xf "${TEMP}/hugo.tar.gz" hugo -C /usr/bin
doas apk add --update libc6-compat libstdc++

Installation of libc6-compat and libstdc++ is required due to changes in Go 1.20.

Tested with

Alpine Linux 3.19
Kernel 6.6.7-0-lts
x86_64

Reference: https://github.com/gohugoio/hugo/issues/10839

2 Likes

Nice, thanks for sharing. Noticed a small typo in your tar command: .tz instead of .gz

Below is a Docker version of this, which also works for for arm64 folks.
You can build the site to a ./public dir on disk with: docker build -o public .

# syntax=docker/dockerfile:1

ARG ALPINE_VERSION=3.19

FROM alpine:${ALPINE_VERSION} AS base

FROM base AS hugo
WORKDIR /tmp/hugo
ARG TARGETARCH
ARG HUGO_VERSION=0.121.1
RUN wget -O "hugo.tar.gz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz"
RUN tar -xf "hugo.tar.gz" hugo -C /usr/bin

FROM base AS build
WORKDIR /src
RUN apk add --update libc6-compat libstdc++
COPY --from=hugo /usr/bin/hugo /bin/hugo
RUN --mount=type=bind,target=.,rw hugo -d /out

FROM scratch
COPY --from=build /out /
1 Like