这是本节的多页打印视图。 点击此处打印.

返回本页常规视图.

安装Hugo

Installation - 安装

https://gohugo.io/installation/

​ 在macOS、Linux、Windows、BSD上,以及任何可以运行Go编译器工具链的机器上都可以安装Hugo。

1 - macOS

macOS

https://gohugo.io/installation/macos/

Install Hugo on macOS.

Editions

Hugo is available in two editions: standard and extended. With the extended edition you can:

  • Encode WebP images (you can decode WebP images with both editions)
  • Transpile Sass to CSS using the embedded LibSass transpiler

We recommend that you install the extended edition.

Prerequisites

Although not required in all cases, Git and Go are often used when working with Hugo.

Git is required to:

Go is required to:

  • Use the Hugo Modules feature
  • Build Hugo from source

Please refer to the Git and Go documentation for installation instructions.

Prebuilt binaries

Prebuilt binaries are available for a variety of operating systems and architectures. Visit the latest release page, and scroll down to the Assets section.

  1. Download the archive for the desired edition, operating system, and architecture
  2. Extract the archive
  3. Move the executable to the desired directory
  4. Add this directory to the PATH environment variable
  5. Verify that you have execute permission on the file

Please consult your operating system documentation if you need help setting file permissions or modifying your PATH environment variable.

If you do not see a prebuilt binary for the desired edition, operating system, and architecture, install Hugo using one of the methods described below.

Package managers

Homebrew

Homebrew is a free and open source package manager for macOS and Linux. This will install the extended edition of Hugo:

1
brew install hugo

MacPorts

MacPorts is a free and open source package manager for macOS. This will install the extended edition of Hugo:

1
sudo port install hugo

Docker

Erlend Klakegg Bergheim graciously maintains Docker images based on images for Alpine Linux, Busybox, Debian, and Ubuntu.

1
docker pull klakegg/hugo

Build from source

To build Hugo from source you must:

  1. Install Git
  2. Install Go version 1.18 or later
  3. Update your PATH environment variable as described in the Go documentation

The install directory is controlled by the GOPATH and GOBIN environment variables. If GOBIN is set, binaries are installed to that directory. If GOPATH is set, binaries are installed to the bin subdirectory of the first directory in the GOPATH list. Otherwise, binaries are installed to the bin subdirectory of the default GOPATH ($HOME/go or %USERPROFILE%\go).

Then build and test:

1
2
go install -tags extended github.com/gohugoio/hugo@latest
hugo version

Comparison

Prebuilt binariesPackage managersDockerBuild from source
Easy to install?✔️✔️✔️✔️
Easy to upgrade?✔️✔️✔️✔️
Easy to downgrade?✔️✔️ 1✔️✔️
Automatic updates?22
Latest version available?✔️✔️✔️✔️

  1. Easy if a previous version is still installed. ↩︎
  2. Possible but requires advanced configuration. ↩︎ ↩︎

另请参阅

2 - Linux

Linux

https://gohugo.io/installation/linux/

​ 在Linux上安装Hugo。

版本

​ Hugo有两个版本:标准版和扩展版。使用扩展版可以:

  • 编码WebP图像(使用两个版本都可以解码WebP图像)
  • 使用内置的LibSass编译器将Sass转换为CSS

​ 我们建议您安装扩展版。

前提条件

​ 虽然并非所有情况下都需要,但在使用Hugo时通常使用Git和Go。

​ 需要Git的情况:

​ 需要Go的情况:

  • 使用Hugo Modules功能
  • 从源代码构建Hugo

​ 请参阅GitGo文档以获取安装说明。

预构建二进制文件

​ 预构建的二进制文件可用于各种操作系统和架构。访问最新版本页面,然后向下滚动到Assets 部分。

  1. 下载所需版本、操作系统和架构的存档
  2. 解压缩存档
  3. 将可执行文件移动到所需目录
  4. 将此目录添加到PATH环境变量中
  5. 验证您对该文件具有执行权限

​ 如果需要帮助设置文件权限或修改PATH环境变量,请参考操作系统文档。

​ 如果您没有看到所需版本、操作系统和架构的预构建二进制文件,请使用以下方法之一安装Hugo。

包管理器

Snap

Snap是Linux的免费开源软件包管理器。Snap包适用于大多数发行版,易于安装并且会自动更新。

​ Hugo snap包是严格隔离的。严格隔离的snap运行在完全隔离的环境中,最小访问级别被认为是始终安全的。您创建和构建的站点必须位于您的主目录内或可移动媒体上。

​ 这将安装Hugo的扩展版:

1
sudo snap install hugo

Homebrew

Homebrew是macOS和Linux的免费开源软件包管理器。这将安装Hugo的扩展版:

1
brew install hugo

存储库包

​ 大多数Linux发行版都维护着一个通用安装应用程序的软件仓库。请注意,这些仓库可能不包含最新版本

Arch Linux

​ 基于Arch Linux的Linux发行版包括EndeavourOSGaruda LinuxManjaro等。这将安装Hugo的扩展版:

1
sudo pacman -S hugo

Debian

​ 基于Debian的Linux发行版包括elementary OSKDE neonLinux LiteLinux MintMX LinuxPop!_OSUbuntuZorin OS等。这将安装Hugo的扩展版:

1
sudo apt install hugo

​ 您也可以从最新版本页面下载Debian包。

Fedora

​ 基于Fedora的Linux发行版包括CentOSRed Hat Enterprise Linux等。这将安装Hugo的扩展版:

1
sudo dnf install hugo

openSUSE

​ 基于openSUSE的Linux发行版包括GeckoLinuxLinux Karmada等。这将安装Hugo的扩展版:

1
sudo zypper install hugo

Solus

​ Solus的Linux发行版在其包存储库中包含Hugo。这将安装Hugo的标准版:

1
sudo eopkg install hugo

Docker

Erlend Klakegg Bergheim慷慨地维护了基于Alpine Linux、Busybox、Debian和Ubuntu的Docker images

1
docker pull klakegg/hugo

从源代码构建

​ 要从源代码构建Hugo,您必须:

  1. 安装 Git
  2. 安装Go版本1.18或更高版本
  3. Go文档中的说明更新PATH环境变量

安装目录由GOPATH和GOBIN环境变量控制。如果设置了GOBIN,那么二进制文件将安装到该目录中。如果设置了GOPATH,则二进制文件将安装到GOPATH列表中第一个目录的bin子目录中。否则,二进制文件将安装到默认GOPATH的bin子目录($HOME/go%USERPROFILE%\go)。

然后构建和测试:

1
2
go install -tags extended github.com/gohugoio/hugo@latest
hugo version

对比

Prebuilt binariesPackage managersRepository packagesDockerBuild from source
Easy to install?✔️✔️✔️✔️✔️
Easy to upgrade?✔️✔️varies✔️✔️
Easy to downgrade?✔️✔️ 1varies✔️✔️
Automatic updates?varies 23
Latest version available?✔️✔️varies✔️✔️

  1. 如果之前安装了旧版本,安装将变得容易。 ↩︎
  2. Snap 包会自动更新。Homebrew 需要高级配置。 ↩︎
  3. 虽然可能,但需要高级配置。 ↩︎

另请参阅

3 - Windows

Windows

https://gohugo.io/installation/windows/

​ 在 Windows 上安装 Hugo。

版本

​ Hugo 有两个版本:标准版和扩展版。使用扩展版,您可以:

  • 将 WebP 图像进行编码(标准版和扩展版都可以解码 WebP 图像)
  • 使用内置的 LibSass 转译器将 Sass 转译为 CSS

​ 我们建议您安装扩展版。

先决条件

​ 虽然在某些情况下不是必需的,但在使用 Hugo 时经常使用 Git 和 Go。

​ 需要Git的情况:

​ 需要Go的情况:

  • 使用Hugo Modules功能
  • 从源代码构建Hugo

​ 请参阅GitGo文档以获取安装说明。

预构建二进制文件

​ 预构建的二进制文件可用于各种操作系统和架构。访问最新版本页面,然后向下滚动到Assets 部分。

  1. 下载所需版本、操作系统和架构的存档
  2. 解压缩存档
  3. 将可执行文件移动到所需目录
  4. 将此目录添加到PATH环境变量中
  5. 验证您对该文件具有执行权限

​ 如果需要帮助设置文件权限或修改PATH环境变量,请参考操作系统文档。

​ 如果您没有看到所需版本、操作系统和架构的预构建二进制文件,请使用以下方法之一安装Hugo。

包管理器

Chocolatey

Chocolatey是 Windows 的一个免费开源软件包管理器。这将安装 Hugo 的扩展版:

1
choco install hugo-extended

Scoop

Scoop是 Windows 的一个免费开源软件包管理器。这将安装 Hugo 的扩展版:

1
scoop install hugo-extended

Winget

Winget是微软的官方免费开源软件包管理器。这将安装 Hugo 的扩展版:

1
winget install Hugo.Hugo.Extended

Docker

Erlend Klakegg Bergheim 慷慨地维护基于 Alpine Linux、Busybox、Debian 和 Ubuntu 的 Docker 映像

1
docker pull klakegg/hugo

从源代码构建

要从源代码构建 Hugo,您必须:

  1. 安装Git
  2. 安装 Go 版本 1.18 或更高版本
  3. 按照 Go 文档中的说明更新 PATH 环境变量。

​ 安装目录由GOPATH和GOBIN环境变量控制。如果设置了GOBIN,则二进制文件将安装到该目录。如果设置了GOPATH,则二进制文件将安装到GOPATH列表中第一个目录的bin子目录中。否则,二进制文件将安装到默认的GOPATH的bin子目录中($HOME/go%USERPROFILE%\go)。

​ 然后进行构建和测试:

1
2
go install -tags extended github.com/gohugoio/hugo@latest
hugo version

​ 在Windows上构建Hugo的扩展版时,还需要安装GCC编译器。请参考这些详细的说明

比较

Prebuilt binariesPackage managersDockerBuild from source
Easy to install?✔️✔️✔️✔️
Easy to upgrade?✔️✔️✔️✔️
Easy to downgrade?✔️✔️ 1✔️✔️
Automatic updates?22
Latest version available?✔️✔️✔️✔️

  1. 如果先前安装了旧版本,则易于安装。↩︎
  2. 可能,但需要高级配置。↩︎ ↩︎

See 另请参阅

4 - BSD

BSD

https://gohugo.io/installation/bsd/

Install Hugo on BSD derivatives.

Editions

Hugo is available in two editions: standard and extended. With the extended edition you can:

  • Encode WebP images (you can decode WebP images with both editions)
  • Transpile Sass to CSS using the embedded LibSass transpiler

We recommend that you install the extended edition.

Prerequisites

Although not required in all cases, Git and Go are often used when working with Hugo.

Git is required to:

Go is required to:

  • Use the Hugo Modules feature
  • Build Hugo from source

Please refer to the Git and Go documentation for installation instructions.

Prebuilt binaries

Prebuilt binaries are available for a variety of operating systems and architectures. Visit the latest release page, and scroll down to the Assets section.

  1. Download the archive for the desired edition, operating system, and architecture
  2. Extract the archive
  3. Move the executable to the desired directory
  4. Add this directory to the PATH environment variable
  5. Verify that you have execute permission on the file

Please consult your operating system documentation if you need help setting file permissions or modifying your PATH environment variable.

If you do not see a prebuilt binary for the desired edition, operating system, and architecture, install Hugo using one of the methods described below.

Repository packages

Most BSD derivatives maintain a repository for commonly installed applications. Please note that these repositories may not contain the latest release.

DragonFly BSD

DragonFly BSD includes Hugo in its package repository. This will install the extended edition of Hugo:

1
sudo pkg install gohugo

FreeBSD

FreeBSD includes Hugo in its package repository. This will install the extended edition of Hugo:

1
sudo pkg install gohugo

NetBSD

NetBSD includes Hugo in its package repository. This will install the extended edition of Hugo:

1
sudo pkgin install go-hugo

OpenBSD

OpenBSD includes Hugo in its package repository. This will prompt you to select which edition of Hugo to install:

1
doas pkg_add hugo

Build from source

To build Hugo from source you must:

  1. Install Git
  2. Install Go version 1.18 or later
  3. Update your PATH environment variable as described in the Go documentation

The install directory is controlled by the GOPATH and GOBIN environment variables. If GOBIN is set, binaries are installed to that directory. If GOPATH is set, binaries are installed to the bin subdirectory of the first directory in the GOPATH list. Otherwise, binaries are installed to the bin subdirectory of the default GOPATH ($HOME/go or %USERPROFILE%\go).

Then build and test:

1
2
go install -tags extended github.com/gohugoio/hugo@latest
hugo version

Comparison

Prebuilt binariesRepository packagesBuild from source
Easy to install?✔️✔️✔️
Easy to upgrade?✔️varies✔️
Easy to downgrade?✔️varies✔️
Automatic updates?varies
Latest version available?✔️varies✔️

另请参阅