How to install Hugo static site generator on Ubuntu 24.04
Build a fast, secure static site using the official binary. This guide covers downloading, extracting, and configuring Hugo for production on Ubuntu 24.04 with Go 1.22.
This guide installs the official Hugo binary on Ubuntu 24.04 to generate static HTML sites. You will configure the environment and build a sample project to verify the setup works correctly.
Prerequisites
- Ubuntu 24.04 LTS or newer
- Go 1.22.x installed (required to compile Hugo if building from source, but we use the binary)
- A standard user account with sudo privileges
- At least 100 MB of free disk space
- Internet connection to download the release
Step 1: Download the official Hugo binary
Download the latest stable version of the Hugo binary directly from the GitHub releases page. The official release ensures you get the most recent features and security patches without needing to compile from source.
curl -LO https://github.com/gohugoio/hugo/releases/download/v0.132.0/hugo_0.132.0_linux-amd64.tar.gz
You will see a progress bar filling up as the download completes. This file contains the compiled binary for Linux x86_64 systems.
Step 2: Extract the binary to a system directory
Extract the downloaded archive to a system directory like /usr/local/bin so the command is available globally. Using /usr/local/bin is standard practice for installing third-party tools that are not managed by the system package manager.
sudo tar -xzf hugo_0.132.0_linux-amd64.tar.gz -C /usr/local/bin
The extraction process places the executable file directly into the bin directory. The file will be named hugo with executable permissions set automatically.
Step 3: Clean up temporary files
Remove the downloaded archive and the temporary directory to free up disk space. Keeping these files serves no purpose after installation and can clutter your system.
sudo rm hugo_0.132.0_linux-amd64.tar.gz
This command deletes the compressed archive from the current directory. Verify the file is gone by listing the directory contents.
Step 4: Create a sample Hugo site
Create a new site directory structure using the built-in init command. This generates the standard file layout including content folders, layouts, and configuration files.
hugo new site mysite
Run the command from your home directory or any preferred location. The command creates a folder named mysite with the necessary subdirectories.
cd mysite
Navigate into the new directory to view the generated structure.
Step 5: Configure the site
Edit the configuration file to set your site title and base URL. Open the config.toml file in your preferred text editor and replace the default values.
hugo config.toml
Replace the content with the following configuration:
baseURL = "https://example.com/"
title = "My Static Site"
theme = "ananke"
Save the file and exit the editor. This configuration defines the domain, site name, and selects a default theme.
Step 6: Create a sample content page
Add a markdown file to the content directory to generate a static HTML page. This file will be converted into a public HTML file during the build process.
hugo new posts/my-first-post.md
Edit the generated file and add the following content:
---
title: "My First Post"
date: 2024-01-01
---
This is my first post.
Save the file. The front matter at the top defines the metadata for the page.
Verify the installation
Run the version command to confirm Hugo is installed correctly and accessible from the terminal. You should see the version number and the Go version it was compiled with.
hugo version
You will see output similar to this:
hugo v0.132.0+extended linux amd64 BuildDate=2024-06-01T12:00:00Z
Generate the static site and serve it locally to test the output. This command builds all content and starts a local server on port 1313.
hugo --source=mysite --destination=public
Open your browser and navigate to http://localhost:1313 to view the rendered HTML. You should see your site title and the content of the first post.
Troubleshooting
Error: command not found
If you run hugo and receive a "command not found" error, the binary was not placed in a directory in your PATH. Ensure you extracted the file to /usr/local/bin or added the custom bin directory to your ~/.bashrc or ~/.zshrc file.
Error: permission denied
If you cannot run the command or write to the directory, your user lacks write permissions. Run the installation commands with sudo or extract the binary to your home directory (/home/youruser/bin) and add that path to your shell profile.
Error: unable to load theme
If the build fails because it cannot find the theme, ensure the theme directory exists in the layouts folder. You can add a theme by creating the directory and copying the theme files, or by specifying a remote theme in the config file using the git URL syntax.
Error: Go module errors
If you encounter Go module errors during a build, ensure you have Go installed. Install Go by downloading the tarball from the official Go website and extracting it to /usr/local/go. Add /usr/local/go/bin to your PATH environment variable and restart your terminal.
Build fails with "error: failed to load"
Check the log output for specific file paths. Often, this indicates a missing image or a broken link in the content. Verify that all image files referenced in the markdown exist in the static/images directory.