hugo on linux

Almost a year ago, we published the instructions for setting up a static site with Hugo. We figured it was about time to check-in with this project again, and as a twist, provide instructions for getting things up and running on Ubuntu Linux.

The steps are quite similar to our Windows install.

  1. Setup Go.
  2. Setup Homembrew.
  3. Install Hugo with Homebrew.
  4. Test Hugo.
  5. Setup Github.
  6. Install mimimo updates. Fix errors.
  7. Push changes. Go Live!

Setup Go

  sudo apt-get install golang

Setup Homembrew

First, Homebrew requires the following packages (build-essential, file, and git):

    sudo apt-get install build-essential
    sudo apt-get file
    sudo apt-get git

With these, we can use fetch and run the Homebrew Install Script:

  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Finally, we need to make sure that Homebrew can be found. These should be added to ~/.profile.

  test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
  test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
  test -r ~/.bash_profile && echo eval" ($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
  echo "eval $($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Install Hugo with Homebrew

  brew install hugo

Test Hugo

Following the instructions from Quickstart, download and add a theme:

  cd quickstart
  git init
  git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
  echo 'theme = "ananke"' >> config.toml

And create an initial post and publish:

  hugo new posts/my-first-post.md

Finally, start the hugo server and open the browser to http://localhost:1313/. If things are working correctly, you should see Hugo running locally.

Setup Github

Our connection to Github was not previously setup on Ubuntu.

First, create an SSH key for GitHub. We followed the guide outlined here).

  Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
  Enter passphrase (empty for no passphrase): [Type a passphrase]
  Enter same passphrase again: [Type passphrase again]

  ssh-keygen -t rsa -b 4096 -C your_email@example.com
  eval "$(ssh-agent -s)"
  ssh-add ~/.ssh/id_rsa

Then, upload SSH Key to GitHub:

  sudo apt-get install xclip

And copy the file to the clipboard:

  xclip -sel clip < ~/.ssh/id_rsa.pub

Next, test the setup and then clone an existing repo:

  ssh -T git@github.com
  git clone git@github.com:USERNAME/Repo.git

In this case:

  git clone git@github.com:alexanderdtaylor/alexanderdtaylor.github.io.git
  git clone git@github.com:alexanderdtaylor/hugo-blog.git

Install Updates & Fix Errors

Then we rf-rm the themes/mimimo directory, and reinstalled the theme.

There were several things that we had personally customized, but didn’t document. They were as follows:

  recent_posts.html
  taxonomy_cloud.html
  layouts/partials/header.html
  hugo-blog/themes/minimo/static/favicon.ico

Hugo will reload the changes on the first three automatically. A hard refresh is needed on the browser to reload the favicon (CTRL+F5 in Firefox).

Lastly, because of other changes in the template, we had to resize the picture on the home page. We did this in a sloppy and hard-coded manner, but it allowed us to quickly move on.

Push changes & go live!

We pushed changes to the git repo for the static site, and then the generating code. The site did not build immediately, so we went into Render and did a clean rebuild. The static site is now up-and-running. We are live. We can now push any changes via Linux and are overall, very pleased.