Wednesday, July 3, 2024
HomeOperating SystemsUbuntuInstall and Use Hugo On Ubuntu 22.04|20.04|18.04

Install and Use Hugo On Ubuntu 22.04|20.04|18.04

In this guide, I’ll take you through the steps to install and use Hugo on Ubuntu 22.04|20.04|18.04 Desktop and Server editions. Hugo has been confirmed to be the fastest open-source static site generator written in Go. Hugo is capable of generating a static site at a speed of <1 ms per page, the average site builds in less than a second. It ships with pre-made templates to make quick work of SEO, commenting, analytics and other functions.

hugo site generator

Hugo supports unlimited content types, taxonomies, menus, dynamic API-driven content, and more, all without plugins. Additionally, you can output your content in multiple formats, including JSON or AMP

Install Hugo On Ubuntu 22.04|20.04|18.04

Hugo can be installed on Ubuntu 22.04|20.04|18.04 by downloading a .deb package or from apt repository.

Installing Hugo On Ubuntu 22.04|20.04|18.04 from apt repository

Update your system apt index and install Hugo:

sudo apt update
sudo apt -y install hugo

You can confirm the location of hugo binary after installation using which

$ which hugo
/usr/bin/hugo

Confirm installed version:

$ hugo version
Hugo Static Site Generator v0.68.3/extended linux/amd64 BuildDate: 2020-03-25T06:15:45Z

Installing Hugo On Ubuntu 22.04|20.04|18.04 from .deb package

To install Hugo on Ubuntu 22.04|20.04|18.04 from Debian package, first, download the latest release from Github releases page https://github.com/hugo/releases/.

Install wget and curl

sudo apt update
sudo apt install curl wget

Remove older version of hugo

sudo apt remove hugo
exit

Select a version that matches your CPU architecture:

curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest \
 | grep  browser_download_url \
 | grep Linux-64bit.deb \
 | grep -v extended \
 | cut -d '"' -f 4 \
 | wget -i -

Then install the package using:

$ sudo dpkg -i hugo*_Linux-64bit.deb
(Reading database ... 107522 files and directories currently installed.)
Preparing to unpack hugo_0.94.2_Linux-64bit.deb ...
Unpacking hugo (0.94.2) over (0.68.3-1) ...
Setting up hugo (0.94.2) ...
Processing triggers for man-db (2.9.1-1) ...

Confirm installed version:

$ hugo version
hugo v0.94.2-48FB9E4D linux/amd64 BuildDate=2022-03-12T10:28:42Z VendorInfo=gohugoio

If the installation was successful, you should be able to use hugo command:

$ hugo --help

Use Hugo on Ubuntu 22.04|20.04|18.04 Linux

Now that Hugo is installed, you can start creating website content. Before that, you’ll need to create new content for your site. In this example, my site is called hugo.neveropen.co.za

$ hugo new site hugo.neveropen.co.za
Congratulations! Your new Hugo site is created in /home/jmutai/hugo.neveropen.co.za.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/, or
   create your own with the "hugo new theme " command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new /.".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.

To create a test page, cd to site directory and use

$ hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>

Example:

$ cd hugo.neveropen.co.za
$ ls 
archetypes config.toml content data layouts static themes

Site content is placed inside content directory

hugo new posts/test-page.md
/home/jmutai/hugo.neveropen.co.za/content/posts/test-page.md created

Add dummy content for test:

$ vim content/posts/test-page.md

Add:

---
title: "Test Page"
date: 2018-07-12T10:17:29Z
draft: true
---

# Hello World

This is my first hugo site, wooo!!

```
hugo_install="success"
if [[ $hugo_install == "success" ]]; then
  echo "Happy me"
```

bye!

Build site:

$ hugo

                   | EN  
+------------------+----+
  Pages            |  3  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  0  
  Processed images |  0  
  Aliases          |  0  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 9 ms

This will create public folder and add content to it. To serve website using hugo build-in server, use:

$ hugo server

                   | EN  
+------------------+----+
  Pages            |  3  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  0  
  Processed images |  0  
  Aliases          |  0  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 10 ms
Watching for changes in /root/hugo.neveropen.co.za/{content,data,layouts,static}
Watching for config changes in /root/hugo.neveropen.co.za/config.toml
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

For self hosting on a web server like Nginx or Apache, copy content inside public directory to your Web server document root.

Also check:

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments