DEV Community

Cover image for A Practical Guide to Installing a Hugo Theme
Daley Mottley
Daley Mottley

Posted on

A Practical Guide to Installing a Hugo Theme

This guide will walk you through the process of installing a theme for your Hugo site. Whether you're new to Hugo themes or just looking for a reliable setup reference, this tutorial has you covered with simple steps and helpful insights.


Table of Contents

  1. Prerequisites
  2. Setting Up Your Hugo Project
  3. Installing the Theme
  4. Using an Alternative Project Directory
  5. How Themes Work in Hugo (Quick Overview)
  6. Updating the Theme
  7. Running Your Site Locally
  8. Conclusion

Prerequisites

You'll need Hugo and Git installed on your computer to get started.

  1. Install Hugo.
  2. Install Git.

After installation, confirm that both are working:

hugo version
git --version
Enter fullscreen mode Exit fullscreen mode

Setting Up Your Hugo Project

If you don’t already have a Hugo project, let’s create one!

  1. Start a Hugo project in a directory called app:
   hugo new site app
Enter fullscreen mode Exit fullscreen mode
  1. Move into your new project:
   cd app
Enter fullscreen mode Exit fullscreen mode

Installing the Theme

You can add a Hugo theme in two main ways: using a Git submodule or downloading it manually.

Method 1: Git Submodule (Best for Easy Updates)

  1. Add the theme to your Hugo project:
   git submodule add https://github.com/theme-author/theme-repo.git themes/theme-folder
Enter fullscreen mode Exit fullscreen mode
  1. Open config.toml (or config.yaml) and set your theme:
   theme = "theme-folder"
Enter fullscreen mode Exit fullscreen mode

Method 2: Manual Download

  1. Download the theme from its GitHub repository and unzip it.
  2. Place the unzipped folder into app/themes/, naming it theme-folder.
  3. Update config.toml:
   theme = "theme-folder"
Enter fullscreen mode Exit fullscreen mode

Using an Alternative Project Directory

If your Hugo project is located in a different directory (e.g., ./app/hugo-site), you’ll just need to adjust paths:

  1. Move to the project root:
   cd ./app/hugo-site
Enter fullscreen mode Exit fullscreen mode
  1. Install the theme as described above in ./app/hugo-site/themes/theme-folder.

  2. In config.toml, set the theme:

   theme = "theme-folder"
Enter fullscreen mode Exit fullscreen mode
  1. Run Hugo from this directory to view your site:
   hugo server -D
Enter fullscreen mode Exit fullscreen mode

How Themes Work in Hugo (Quick Overview)

Themes in Hugo bundle templates, layouts, and assets, giving your site a professional look with minimal setup. When Hugo builds your site, it merges the theme files with your content files to create the final website.


Updating the Theme

If you installed the theme as a Git submodule, updating is straightforward:

  1. Navigate to the theme folder:
   cd app/themes/theme-folder
Enter fullscreen mode Exit fullscreen mode
  1. Pull the latest updates:
   git pull origin main
Enter fullscreen mode Exit fullscreen mode
  1. Return to your project directory:

    cd ../..
    
  2. Commit the update:

   git add themes/theme-folder
   git commit -m "Update theme to latest version"
Enter fullscreen mode Exit fullscreen mode

For manual installs, just replace the old theme folder with a fresh download.


Running Your Site Locally

Once the theme is installed, run your site locally to preview it:

hugo server -D
Enter fullscreen mode Exit fullscreen mode

Check out http://localhost:1313 in your browser to see the theme in action.


Conclusion

With these steps, you're set up to install any Hugo theme with ease! For more theme customization options and resources, explore the Hugo documentation.

Enjoy building your beautifully themed Hugo site!

Top comments (0)