GETTING STARTED WITH HUGO - INSTALLATION AND FIRST SITE
Introduction
Hugo is the world's fastest static site generator, capable of building thousands of pages in seconds. In this first part of our series, we'll get Hugo installed and create our first site from scratch.
Why Hugo?
Before we dive in, let's understand why Hugo has become so popular:
- Speed: Builds sites in milliseconds
- Flexibility: Complete control over HTML output
- Simplicity: No database, just plain text files
- Security: Static files mean no server vulnerabilities
- Cost: Free hosting on GitHub Pages, Netlify, etc.
Prerequisites
You'll need:
- A terminal/command line
- A text editor (VS Code, Sublime Text, etc.)
- Git (for version control)
- Basic understanding of HTML and Markdown
Installing Hugo
On macOS
Using Homebrew:
brew install hugoOn Linux
Using package manager (Ubuntu/Debian):
sudo apt-get install hugoOr download the latest release from Hugo's GitHub releases.
On Windows
Using Chocolatey:
choco install hugo -confirm Or download the Windows installer from the official website.
Verify Installation
Check your Hugo version:
hugo versionYou should see output like:
hugo v0.152.2+extended linux/amd64 BuildDate=unknownImportant: Make sure you have the extended version of Hugo, which includes support for processing Sass/SCSS.
Creating Your First Site
Step 1: Generate a New Site
hugo new site my-portfolio
cd my-portfolioThis creates a new Hugo site with the following structure:
my-portfolio/
├── archetypes/ # Content templates
├── assets/ # Files to be processed (CSS, JS)
├── content/ # Your content files
├── data/ # Data files for generating content
├── layouts/ # Template files
├── static/ # Static files (images, fonts)
├── themes/ # Theme directory
└── hugo.toml # Site configurationStep 2: Understanding the Structure
Let's explore each directory:
content/ - This is where your Markdown files live. Each file becomes a page on your site.
layouts/ - HTML templates that define how your content is rendered.
static/ - Files that are copied directly to the output (images, CSS, JavaScript).
hugo.toml - Main configuration file for your site.
Step 3: Basic Configuration
Open hugo.toml and update it:
baseURL = "https://yourusername.github.io"
languageCode = "en-us"
title = "My Portfolio"
theme = "" # We'll add this later
[ params ]
author = "Your Name"
description = "Personal portfolio and blog" Step 4: Create Your First Content
Create a simple homepage:
hugo new _index.mdEdit content/_index.md:
---
title : "Welcome"
date : 2024-12-25
---
# Welcome to My Site
This is my first Hugo site!Step 5: Create a Simple Layout
Since we don't have a theme yet, let's create a basic layout.
Create layouts/_default/baseof.html:
<!DOCTYPE html >
< html lang ="{{ .Site.LanguageCode }} ">
< head >
< meta charset ="UTF-8 ">
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
< title > {{ .Title }} | {{ .Site.Title }}</ title >
</ head >
< body >
< header >
< h1 > {{ .Site.Title }}</ h1 >
< nav >
< a href ="/ "> Home</ a >
</ nav >
</ header >
< main >
{{ block "main" . }}{{ end }}
</ main >
< footer >
< p > © {{ now.Year }} {{ .Site.Params.author }}</ p >
</ footer >
</ body >
</ html > Create layouts/index.html:
{{ define "main" }}
< div class ="content ">
{{ .Content }}
</ div >
{{ end }}Step 6: Run the Development Server
Start Hugo's built-in server:
hugo serverYou should see output like:
Web Server is available at http://localhost:1313/
Press Ctrl+C to stopOpen your browser and visit http://localhost:1313 - you'll see your site!
Understanding Hugo's Directory Structure
Content Organization
Hugo uses the content directory structure to determine URLs:
content/
├── _index.md → /
├── about.md → /about/
└── blog/
├── _index.md → /blog/
└── first-post.md → /blog/first-post/Front Matter
Every content file starts with front matter - metadata about the page:
---
title : "Page Title"
date : 2024-12-25
draft : false
tags : [ "hugo" , "tutorial" ]
--- Template Lookup Order
Hugo looks for templates in a specific order. For the homepage:
layouts/index.htmllayouts/_default/list.html
For regular pages:
layouts/_default/single.html
Next Steps
In this tutorial, you learned:
- ✅ How to install Hugo
- ✅ Creating a new site
- ✅ Understanding the directory structure
- ✅ Basic configuration
- ✅ Creating your first content
- ✅ Running the development server
Coming Up Next
In Part 2: Content Organization Strategies, we'll explore:
- Sections and taxonomies
- Front matter best practices
- Creating multiple content types
- Organizing content for scale
Quick Reference
# Create new site
hugo new site mysite
# Create new content
hugo new posts/my-post.md
# Start development server
hugo server
# Build production site
hugo --minify
# Check version
hugo versionCommon Issues
Problem: hugo: command not found
Solution: Hugo isn't in your PATH. Reinstall or add Hugo's location to PATH.
Problem: Site builds but shows no content
Solution: Check that draft: false in your content front matter.
Problem: Changes not appearing
Solution: Hugo server caches. Restart with hugo server --noHTTPCache
Resources
Ready to continue? Move on to Part 2: Content Organization Strategies to learn how to structure your content for growth!