Important
建议先通读全文了解基本流程再进行
Hugo 在 GitHub 上并没有适用于 Android Termux 的 aarch64 架构的二进制文件,因此,需要手动在 Termux 上自行编译安装。
安装 Go
使用以下命令来安装 Go:
[~]$ pkg install golang
检查是否安装成功,正常输出 go 版本号即为成功:
$ go version
go version go1.26.5 android/arm64
编译 Hugo
在 Hugo 的 GitHub 仓库中,README 文件贴出了手动编译的命令。源码是从 GitHub 下载,所以请确认网络环境状况或者使用镜像网站。
因为我使用的 Hugo 主题是 hugo-theme-reimu 所以我要安装拓展版本(Extended edition)。安装拓展版本需要保证有 GCC 或者 Clang 安装,如果没有,运行pkg install clang即可。
然后执行以下命令进行拓展版本的编译:
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest
跑完这一大串就应该编译好了, 本人的麒麟 970 芯片只花了 58 秒就编译好了,你也来试试吧
[~]$ CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest
go: downloading github.com/gohugoio/hugo v0.164.0 go: downloading github.com/bep/godartsass/v2 v2.5.0 go: downloading github.com/bep/golibsass v1.2.0 go: downloading github.com/pelletier/go-toml/v2 v2.4.3 go: downloading github.com/spf13/afero v1.15.0 go: downloading github.com/tdewolff/parse/v2 v2.8.12 go: downloading github.com/bep/logg v0.4.0 go: downloading github.com/fatih/color v1.18.0 go: downloading github.com/alecthomas/chroma/v2 v2.27.0 go: downloading github.com/bep/clocks v0.5.0 go: downloading github.com/bep/debounce v1.2.0 go: downloading github.com/bep/lazycache v0.8.1 go: downloading github.com/bep/mclib v1.20401.20400 go: downloading github.com/bep/overlayfs v0.11.0 go: downloading github.com/fsnotify/fsnotify v1.9.0 go: downloading github.com/bep/simplecobra v0.7.0 go: downloading github.com/goccy/go-yaml v1.19.2 go: downloading github.com/spf13/cobra v1.10.2 go: downloading github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c go: downloading github.com/spf13/fsync v0.10.1 go: downloading github.com/spf13/pflag v1.0.10 go: downloading go.uber.org/automaxprocs v1.5.3 go: downloading golang.org/x/sync v0.21.0 go: downloading golang.org/x/text v0.38.0 go: downloading github.com/cespare/xxhash/v2 v2.3.0 go: downloading github.com/gohugoio/hashstructure v0.6.0 go: downloading github.com/mattn/go-isatty v0.0.22 go: downloading github.com/mattn/go-colorable v0.1.14 go: downloading google.golang.org/protobuf v1.36.11
go: downloading github.com/hashicorp/golang-lru/v2 v2.0.7
go: downloading github.com/dlclark/regexp2/v2 v2.2.1
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/bep/helpers v0.12.0
go: downloading github.com/bep/golocales v0.2.0
go: downloading github.com/spf13/cast v1.10.0
go: downloading github.com/gobwas/glob v0.2.3
go: downloading github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
go: downloading github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
go: downloading github.com/gohugoio/go-radix v1.2.0
go: downloading github.com/jdkato/prose v1.2.1
go: downloading github.com/dlclark/regexp2 v1.12.0
go: downloading github.com/kyokomi/emoji/v2 v2.2.13
go: downloading github.com/olekukonko/tablewriter v1.1.4
go: downloading github.com/bep/gitmap v1.9.0
go: downloading github.com/frankban/quicktest v1.14.6
go: downloading github.com/gobuffalo/flect v1.0.3
go: downloading github.com/hairyhenderson/go-codeowners v0.7.0
go: downloading github.com/yuin/goldmark v1.8.2
go: downloading golang.org/x/tools v0.47.0
go: downloading github.com/rogpeppe/go-internal v1.15.0
go: downloading github.com/gorilla/websocket v1.5.3
go: downloading golang.org/x/mod v0.37.0
go: downloading github.com/clbanning/mxj/v2 v2.7.0
go: downloading github.com/niklasfasching/go-org v1.9.1
go: downloading github.com/bits-and-blooms/bitset v1.24.5
go: downloading golang.org/x/sys v0.46.0
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.6
go: downloading go.yaml.in/yaml/v3 v3.0.4
go: downloading github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
go: downloading github.com/gohugoio/httpcache v0.8.0
go: downloading github.com/tdewolff/minify/v2 v2.24.13
go: downloading github.com/bep/imagemeta v0.17.2
go: downloading github.com/gohugoio/gift v0.2.0
go: downloading github.com/makeworld-the-better-one/dither/v2 v2.4.0
go: downloading golang.org/x/image v0.43.0
go: downloading github.com/muesli/smartcrop v0.3.0
go: downloading github.com/tetratelabs/wazero v1.12.0
go: downloading github.com/bep/textandbinarywriter v0.1.0
go: downloading github.com/marekm4/color-extractor v1.2.1
go: downloading github.com/mattn/go-runewidth v0.0.19
go: downloading github.com/olekukonko/errors v1.2.0
go: downloading github.com/olekukonko/ll v0.1.6
go: downloading github.com/evanw/esbuild v0.28.1
go: downloading github.com/gohugoio/go-i18n/v2 v2.1.3-0.20251018145728-cfcc22d823c6
go: downloading golang.org/x/net v0.56.0
go: downloading github.com/google/go-cmp v0.7.0
go: downloading github.com/kr/pretty v0.3.1
go: downloading software.sslmate.com/src/go-pkcs12 v0.7.0
go: downloading github.com/russross/blackfriday/v2 v2.1.0
go: downloading github.com/bep/tmc v0.6.0
go: downloading github.com/gohugoio/hugo-goldmark-extensions/extras v0.7.0
go: downloading github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.5.0
go: downloading github.com/microcosm-cc/bluemonday v1.0.27
go: downloading github.com/yuin/goldmark-emoji v1.0.6
go: downloading github.com/clipperhouse/uax29/v2 v2.6.0
go: downloading github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6
go: downloading github.com/clipperhouse/displaywidth v0.10.0
go: downloading rsc.io/qr v0.2.0
go: downloading github.com/bep/goat v0.5.0
go: downloading github.com/getkin/kin-openapi v0.140.0
go: downloading github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.2
go: downloading github.com/bep/goportabletext v0.2.0
go: downloading github.com/kr/text v0.2.0
go: downloading golang.org/x/crypto v0.53.0
go: downloading github.com/aymerick/douceur v0.2.0
go: downloading github.com/JohannesKaufmann/dom v0.3.1
go: downloading github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
go: downloading github.com/go-openapi/jsonpointer v0.22.5
go: downloading github.com/oasdiff/yaml v0.1.0
go: downloading github.com/gorilla/css v1.0.1
go: downloading github.com/go-openapi/swag/jsonname v0.25.5
go: downloading github.com/oasdiff/yaml3 v0.0.13
不出意外,编译好的 Hugo 会在~/go/bin/里面,检查一下:
$ ~/go/bin/hugo version
hugo v0.164.0+extended android/arm64 BuildDate=unknown
如果你看到类似的输出,恭喜你,编译好了。不过为了方便,执行
[~]$ cp ~/go/bin/hugo ~/../usr/bin/
就可以随意调用 Hugo 了。
结语
话说是我的原因吗?从 GitHub 下载的 Hugo 二进制文件,已经是 arm64 的,但还是跑不起来,所以只能自己编译。大佬可以给我发邮件讲解一下😁
如果你急需在 Termux 上使用 Hugo 并且编译条件不好,可以发急邮到chankeichow2008@outlook.com给我,如果我看到了,会把编译好的二进制文件发给你。
说些什么吧!