Written by: Geoffrey Callaghan

how to get started in hugo

How To Get Started In Hugo

Getting started with Hugo, a fast and flexible static site generator, is relatively straightforward. Here’s a step-by-step guide to help you set up your first Hugo website:

1. Install Hugo

First, you need to install Hugo. You can download it from the official Hugo releases page or use a package manager for your operating system.

  • For macOS:

    brew install hugo
  • For Windows:

    You can use Chocolatey:

    choco install hugo -confirm
  • For Linux:

    Follow the instructions on the official installation guide.

2. Create a New Site

Once Hugo is installed, you can create a new site by running:

hugo new site my-website

This will create a new directory called my-website with the necessary folder structure.

3. Add a Theme

Hugo uses themes to manage the appearance of your site. You can find a list of themes on the Hugo themes website. To add a theme:

  1. Change to your website’s directory:

    cd my-website
  2. Initialize a new Git repository (required for adding themes via Git):

    git init
  3. Add the theme as a Git submodule. For example, to add the “Ananke” theme:

    git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
  4. Open the config.toml file in your site’s root directory and add the theme:

    theme = "ananke"

4. Create Your First Content

Now you can create your first piece of content. Hugo uses Markdown files for content:

hugo new posts/my-first-post.md

This creates a new Markdown file in the content/posts directory. Open the file and add some content. Here’s an example:

---
title: "My First Post"
date: 2023-06-15T12:00:00Z
draft: true
---

This is my first post on my new Hugo site!

Change draft to false when you’re ready to publish.

5. Build and Serve Your Site

You can build your site and start a local server to see it in action:

hugo server -D

The -D flag includes content marked as draft. Open your web browser and go to http://localhost:1313 to see your site.

6. Customize Your Site

You can customize your site by editing the configuration file (config.toml) and adding more content. Here are some common customizations:

  • Change the title:

    title = "My Awesome Hugo Site"
  • Add a menu:

    [[menu.main]]
      name = "Home"
      url = "/"
      weight = 1
    
    [[menu.main]]
      name = "Posts"
      url = "/posts/"
      weight = 2
  • Add static files:

    Place static files (e.g., images, CSS, JavaScript) in the static directory. These will be served directly.

7. Deploy Your Site

When you’re ready to deploy your site, you can generate the static files:

hugo

This will create a public directory with all the files you need to deploy. You can then upload these files to your web server or use a platform like GitHub Pages, Netlify, or Vercel.

Resources

By following these steps, you’ll be able to set up and customize a Hugo site tailored to your needs. Happy building!