Marvin Tan Software Tester • OSCP Wannabe • Open Source Lover

Install Hugo on macOS

#macos #hugo #homebrew Aug 5, 2018 10 min
Table of Contents:

Step 1: Install Homebrew on macOS

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system.

Open Terminal app and type:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Output
Marvins-MacBook-Pro:~ marvin$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Ignoring commonmarker-0.17.9 because its extensions are not built.  Try: gem pristine commonmarker --version 0.17.9
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown marvin /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 545eb91c8 Merge pull request #4599 from reitermarkus/download-cache-directory
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/marvin/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation:
    https://docs.brew.sh
Marvins-MacBook-Pro:~ marvin$

Step 2: Install Git Using Homebrew:

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

brew install git

Output
Marvins-MacBook-Pro:~ marvin$ brew install git
==> Downloading https://homebrew.bintray.com/bottles/git-2.18.0.high_sierra.bottle.tar.gz
Already downloaded: /Users/marvin/Library/Caches/Homebrew/git-2.18.0.high_sierra.bottle.tar.gz
==> Pouring git-2.18.0.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git
==> Summary
🍺  /usr/local/Cellar/git/2.18.0: 1,488 files, 295.6MB
Marvins-MacBook-Pro:~ marvin$

Step 3: Install Hugo using Homebrew

Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility.

brew install hugo

Output
Marvins-MacBook-Pro:~ marvin$ brew install hugo
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
amtk                          gradio                        node_exporter                 schema-evolution-manager
beagle                        lf                            phpmyadmin                    sonarqube-lts
eless                         libimagequant                 prettier                      squashfuse
erlang@20                     mkcert                        pyside                        thors-serializer
gptfdisk                      mongodb@3.6                   python-yq                     xcodegen
==> Updated Formulae
coreutils ✔                   faas-cli                      libmagic                      py3cairo
gnupg ✔                       fabric                        libmspub                      pyenv
gnutls ✔                      fades                         libosinfo                     pygitup
iperf3 ✔                      fakeroot                      libosmium                     pygobject3
isl ✔                         fastqc                        libpeas                       pyinvoke
libgpg-error ✔                fb-client                     libphonenumber                pypy
libyaml ✔                     fdclone                       libpng                        pyqt
npth ✔                        fdroidserver                  libpst                        python
openssl ✔                     feh                           libqalculate                  python@2
readline ✔                    ffmpeg                        libraw                        pytouhou
abcde                         ffmpeg@2.8                    librdkafka                    qbs
abcm2ps                       fftw                          librealsense                  qcachegrind
abcmidi                       file-formula                  libspectrum                   qjackctl
ack                           file-roller                   libtensorflow                 qpdf
acpica                        fio                           libtiff                       qpid-proton
adr-tools                     firebase-cli                  libtomcrypt                   qscintilla2
agda                          flintrock                     libtorrent-rasterbar          qt
aircrack-ng                   flow                          libtrace                      qtkeychain
algernon                      fluent-bit                    libuninameslist               quicktype
allure                        flyway                        libuv                         r
alluxio                       fmt                           libvirt                       rabbitmq
amazon-ecs-cli                fn                            libvisio                      radare2
amber                         folly                         libwebsockets                 rancher-cli
angle-grinder                 fonttools                     link-grammar                  rawtoaces
angular-cli                   fop                           linkerd                       raylib
annie                         ford                          liquibase                     rclone
ansible                       fortio                        liquigraph                    re2
ansible-lint                  fq                            llvm                          rebar@3
ansiweather                   freeciv                       llvm@5                        ripgrep
ant                           freeimage                     lmod                          rocksdb
ant@1.9                       freeling                      logtalk                       roll
apache-flink                  freetds                       lsof                          rom-tools
apache-opennlp                fribidi                       lua                           root
apache-zeppelin               frugal                        lxc                           rsyslog
app-engine-java               fruit                         lynis                         rtv
arangodb                      fselect                       lynx                          ruby-build
ark                           fswatch                       macvim                        rust
armadillo                     fuse-emulator                 mafft                         rustup-init
arp-scan                      fuseki                        magic-wormhole                s3cmd
arpack                        futhark                       mame                          s3fs
artifactory                   fwup                          mapcrafter                    sagittarius-scheme
asciinema                     gammaray                      mapnik                        samtools
asdf                          gauche                        mariadb                       sane-backends
ask-cli                       gauge                         mariadb@10.0                  sbcl
assh                          gcc                           mariadb@10.1                  sbt
atlassian-cli                 gcovr                         mariadb@10.2                  sbtenv
augustus                      gdal                          math-comp                     sccache
aws-elasticbeanstalk          gdb                           maven                         scipy
aws-sdk-cpp                   gdbm                          maxwell                       scour
aws-shell                     gdcm                          mbedtls                       scw
awscli                        gegl                          mdp                           sdb
azure-cli                     geoserver                     megacmd                       selenium-server-standalone
b2-tools                      get-flash-videos              megatools                     seqtk
babel                         get_iplayer                   memcached                     sfk
babl                          gibo                          menhir                        shadowsocks-libev
bacula-fd                     gifski                        mercurial                     shairport-sync
ballerina                     git                           meson                         shared-mime-info
bandcamp-dl                   git-annex                     meson-internal                shellharden
bareos-client                 git-cola                      mikutter                      shfmt
baresip                       git-ftp                       mill                          shibboleth-sp
bartycrouch                   git-lfs                       mimic                         shyaml
bats-core                     git-quick-stats               minimal-racket                sile
bazel                         gitbucket                     mint                          silk
bcftools                      giter8                        mitmproxy                     simgrid
beast                         gitlab-runner                 mkdocs                        singular
bench                         gjstest                       mkl-dnn                       sip
bettercap                     globus-toolkit                mkvtoolnix                    sipp
bgpstream                     gmt                           mlt                           siril
bibutils                      gnatsd                        modd                          skaffold
binaryen                      gnome-builder                 modules                       skafos
bind                          gnome-latex                   monero                        skinny
binutils                      gnu-prolog                    monetdb                       snakemake
biogeme                       gnu-smalltalk                 mongo-c-driver                snapcraft
bit                           gnu-units                     mongo-cxx-driver              solr
bitcoin                       gnuradio                      mongodb                       sonarqube
bitrise                       go-bindata                    mono                          sord
bitwarden-cli                 go-jira                       mosh                          sourcekitten
blackbox                      go-statik                     mpd                           sourcery
blockhash                     gobuster                      mpop                          sphinx-doc
bluepill                      goenv                         mps-youtube                   spotbugs
boost-python3                 gomplate                      mr                            sqlmap
botan                         gopass                        mrtg                          squid
brew-cask-completion          goreleaser                    mutt                          sratoolkit
brotli                        gosu                          mvtools                       sshguard
buildifier                    gr-osmosdr                    mypy                          sshrc
buku                          gradle                        mysql                         sslsplit
byteman                       grafana                       mysql-client                  streamlink
bzt                           graph-tool                    mysql@5.5                     stunnel
cabextract                    graphicsmagick                mysql@5.6                     subversion
caffe                         grib-api                      mysql@5.7                     suite-sparse
cake                          gron                          nagios                        sundials
camlp4                        groonga                       natalie                       supersonic
camlp5                        groovy                        nativefier                    suricata
capstone                      groovysdk                     nats-streaming-server         swift-protobuf
cargo-completion              grpc                          neko                          swiftformat
carthage                      grv                           neofetch                      swiftlint
cassandra                     gsoap                         neomutt                       syncthing
castxml                       gspell                        neovim                        sysbench
ccextractor                   gst-editing-services          nestopia-ue                   sysdig
ccrypt                        gst-libav                     net-snmp                      talloc
ceres-solver                  gst-plugins-bad               netpbm                        tarantool
certbot                       gst-plugins-base              newsboat                      taskell
cfengine                      gst-plugins-good              nginx                         tbb
cfr-decompiler                gst-plugins-ugly              nifi                          tbox
cglm                          gst-python                    nifi-registry                 tectonic
cgrep                         gst-rtsp-server               node                          telegraf
chakra                        gst-validate                  node-build                    teleport
charm                         gstreamer                     node@8                        tepl
checkstyle                    gtk-vnc                       nodeenv                       terragrunt
chrome-cli                    gtksourceview3                nsd                           tesseract
chronograf                    gtksourceview@4               nss                           the_platinum_searcher
cimg                          gupnp                         ntl                           thefuck
circleci                      gutenberg                     nuget                         tig
citus                         gwyddion                      numpy                         tiger-vnc
clamav                        hadolint                      nuxeo                         tile38
clblast                       hana                          nvc                           tippecanoe
clingo                        handbrake                     nzbget                        tkdiff
clojure                       haproxy                       ocaml                         tmux-xpanes
clojurescript                 harfbuzz                      ocaml-num                     tmuxinator-completion
closure-compiler              hashcat                       ocamlbuild                    todolist
cmake                         heroku                        ocamlsdl                      todoman
cockroach                     hevea                         ocrmypdf                      tomcat
codec2                        hfstospell                    octave                        tomcat@8
cointop                       highlight                     odpi                          tor
collectd                      hive                          ola                           tox
commandbox                    hledger                       ompl                          traefik
conan                         hlint                         open-mpi                      trafficserver
confluent-oss                 hopenpgp-tools                open-scene-graph              trash
conjure-up                    hss                           openapi-generator             trezor-agent
consul                        htslib                        openblas                      triton
consul-backinator             httpd                         opencoarrays                  ttfautohint
container-diff                httpie                        opencv                        tup
convox                        hub                           opendetex                     twoping
coq                           hugo                          openfortivpn                  twtxt
couchdb                       hyperfine                     openh264                      txr
credstash                     hyperscan                     openimageio                   typescript
creduce                       i2p                           openjazz                      u-boot-tools
cromwell                      icu4c                         openrct2                      uhd
cryptol                       igv                           opensaml                      unbound
csvkit                        imagemagick                   openshift-cli                 unp64
csvprintf                     imagemagick@6                 ortp                          unrar
csvtomd                       influxdb                      osm-pbf                       upscaledb
cucumber-cpp                  ipfs                          osquery                       uptimed
curl                          ipython                       overmind                      urh
cython                        ipython@5                     pacapt                        utf8proc
dar                           itex2mml                      packer                        util-linux
darcs                         jena                          packmol                       uwsgi
darksky-weather               jenkins                       paket                         vagrant-completion
dartsim                       jenkins-job-builder           pandoc                        vala
datomic                       jenkins-lts                   pandoc-crossref               vapoursynth
dbus                          jetty                         pango                         vault
dcd                           jetty-runner                  parallel                      vcftools
dcm2niix                      jfrog-cli-go                  parallelstl                   vdirsyncer
dcos-cli                      jhipster                      pari                          vegeta
dcraw                         jlog                          passenger                     vert.x
dep                           joplin                        pazpar2                       vim
dependency-check              jpeg-archive                  pdftoedn                      vim@7.4
dfix                          jpeg-turbo                    pdftoipe                      vips
dfmt                          json-fortran                  pegtl                         vnu
dhall-json                    jsonnet                       percona-server-mongodb        vowpal-wabbit
dialog                        jsonrpc-glib                  percona-toolkit               vsts-cli
diff-pdf                      juju                          percona-xtrabackup            wabt
diffoscope                    juju-wait                     perl                          wandio
digdag                        jump                          petsc                         webpack
direnv                        jupyter                       pgcli                         webtorrent-cli
dislocker                     just                          pgloader                      weechat
distcc                        kaitai-struct-compiler        pgplot                        whois
django-completion             keepassc                      pgpool-ii                     widelands
dlib                          keepkey-agent                 pgroonga                      wildfly-as
dmd                           kerl                          phoronix-test-suite           wine
dnscrypt-proxy                khal                          php                           wiredtiger
dnsdist                       khard                         php-code-sniffer              wireguard-tools
docfx                         kitchen-sync                  php-cs-fixer                  wireshark
docker                        knot                          php@5.6                       wolfssl
docker-completion             knot-resolver                 php@7.0                       wrangler
docker-compose                kompose                       php@7.1                       wtf
docker-compose-completion     kops                          phplint                       xapian
dovecot                       kotlin                        phpunit                       xdot
dscanner                      krakend                       pianobar                      xml-security-c
dtc                           kube-aws                      picard-tools                  xml-tooling-c
dub                           kubecfg                       pilosa                        xmrig
duply                         kubeless                      pipenv                        xonsh
dwdiff                        kubernetes-cli                planck                        xtensor
dxpy                          lablgtk                       plantuml                      yamllint
dynare                        landscaper                    platformio                    yarn
e2fsprogs                     languagetool                  pmd                           yaws
eccodes                       latex2rtf                     pony-stable                   yaz
efl                           ldc                           ponyc                         ykman
eigen                         lensfun                       poppler                       yle-dl
ejabberd                      libccd                        pre-commit                    you-get
elixir                        libcdr                        prest                         youtube-dl
elvish                        libcouchbase                  presto                        yq
emscripten                    libdazzle                     progress                      zabbix
ephemeralpg                   libdill                       prometheus                    zanata-client
eprover                       libdvbpsi                     proselint                     zbackup
erlang                        libextractor                  protobuf                      zebra
esniper                       libfixbuf                     protobuf-c                    zimg
etcd                          libfreehand                   protobuf-swift                znapzend
ethereum                      libgit2                       protobuf@2.6                  znc
etsh                          libgphoto2                    proxychains-ng                zorba
exercism                      libheif                       pspg                          zstd
exploitdb                     libical                       pulseaudio
f3                            liblcf                        py2cairo
==> Renamed Formulae
cdiff -> ydiff                          crystal-lang -> crystal                 saltstack -> salt
==> Deleted Formulae
artifactory-cli-go                                           wry

==> Downloading https://homebrew.bintray.com/bottles/hugo-0.46.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring hugo-0.46.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/hugo/0.46: 32 files, 54.9MB
Marvins-MacBook-Pro:~ marvin$

Step 4: Create a New Site

To create a new site, type:

hugo new site mysite

Output
Marvins-MacBook-Pro:~ marvin$ hugo new site mysite
Congratulations! Your new Hugo site is created in /Users/marvin/mysite.

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 <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.
Marvins-MacBook-Pro:~ marvin$

This will create a new directory with a name mysite. That directory will have the correct structure, but no content or theme yet.

Go to that directory by typing:

cd mysite

Output
Marvins-MacBook-Pro:~ marvin$ cd mysite
Marvins-MacBook-Pro:mysite marvin$

List the contents of mysite directory by typing:

ls

Output
Marvins-MacBook-Pro:mysite marvin$ ls
archetypes	config.toml	content		data		layouts		static		themes
Marvins-MacBook-Pro:mysite marvin$

Step 5: Install Themes

You can install available Hugo themes by cloning its repository.

Go to https://themes.gohugo.io/ to see all themes.

Hugo Themes

This example will use Hugo Bootstrap theme. This is a simple Hugo theme using Bootstrap v4.

Image of Hugo Bootstrap Theme

Click download

It will go to the theme’s repository. Hugo Bootstrap’s repository is hosted on Github.

Image of Hugo Bootstrap Repository

Click Clone or download then copy the URL.

Using git clone command, copy the files from the repository by typing:

git clone https://github.com/Xzya/hugo-bootstrap.git themes/hugo-bootstrap

Output
Marvins-MacBook-Pro:mysite marvin$ git clone https://github.com/Xzya/hugo-bootstrap.git themes/hugo-bootstrap
Cloning into 'themes/hugo-bootstrap'...
remote: Counting objects: 180, done.
remote: Total 180 (delta 0), reused 0 (delta 0), pack-reused 180
Receiving objects: 100% (180/180), 399.50 KiB | 574.00 KiB/s, done.
Resolving deltas: 100% (75/75), done.
Marvins-MacBook-Pro:mysite marvin$

This will create a new folder hugo-bootstrap under themes and will copy all files from the repository to it.

Check the files under themes/hugo-bootstrap by typing:

ls themes/hugo-bootstrap

Output
Marvins-MacBook-Pro:mysite marvin$ ls themes/hugo-bootstrap
LICENSE.md	README.md	exampleSite	i18n		images		layouts		static		theme.toml
Marvins-MacBook-Pro:mysite marvin$

Copy all the contents of exampleSite from themes folder to root directory by typing:

cp -r themes/hugo-bootstrap/exampleSite/* .

Output
Marvins-MacBook-Pro:mysite marvin$ cp -r themes/hugo-bootstrap/exampleSite/* .
Marvins-MacBook-Pro:mysite marvin$

Step 6: Run on Localhost

Check if all is working. Hugo comes with a built-in live server. To run it locally, type:

hugo server

Output
Marvins-MacBook-Pro:mysite marvin$ hugo server

                   | DE | EN | ES
+------------------+----+----+----+
  Pages            | 34 | 36 | 34
  Paginator pages  |  0 |  2 |  0
  Non-page files   |  0 |  0 |  0
  Static files     |  1 |  1 |  1
  Processed images |  0 |  0 |  0
  Aliases          | 15 | 15 | 15
  Sitemaps         |  2 |  1 |  1
  Cleaned          |  0 |  0 |  0

Total in 156 ms
Watching for changes in /Users/marvin/mysite/{content,data,layouts,static,themes}
Watching for config changes in /Users/marvin/mysite/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

Go to browser and type in the URL http://localhost:1313/

Image of Hugo Working

Stop the server by pressing Ctrl+C

Step 7: Create New Post

Create a new post by typing:

hugo new posts/hello-world.md

Output
Marvins-MacBook-Pro:mysite marvin$ hugo new posts/hello-world.md
/Users/marvin/mysite/content/post/hello-world.md created
Marvins-MacBook-Pro:mysite marvin$

This will create a new file hello-world.md under content/post folder

View the content of hello-world.md by typing:

cat content/post/hello-world.md

Output
Marvins-MacBook-Pro:mysite marvin$ cat content/post/hello-world.md
---
title: "Hello World"
date: 2018-08-05T1804+12:00
draft: true
---

Marvins-MacBook-Pro:mysite marvin$

By default, a new post will be created as a draft. Edit default.md under archetypes directory to change this default behavior.

Edit the file hello-world.md by typing:

vi content/post/hello-world.md

Output
Marvins-MacBook-Pro:mysite marvin$ vi content/post/hello-world.md

Change draft: true to draft: false and add weight: 1 to make it first in the list. Finally, write some text.

Output
---
title: "Hello World"
date: 2018-08-05T1804+12:00
draft: false
weight: 1
---

Hello world! Welcome to my new site. Please comeback some other time when I've written something worth your time. Thanks for reading!

Run the server and check new post by typing:

hugo server

Output
Marvins-MacBook-Pro:mysite marvin$ hugo server

                   | EN | ES | DE
+------------------+----+----+----+
  Pages            | 37 | 34 | 34
  Paginator pages  |  2 |  0 |  0
  Non-page files   |  0 |  0 |  0
  Static files     |  1 |  1 |  1
  Processed images |  0 |  0 |  0
  Aliases          | 15 | 15 | 15
  Sitemaps         |  2 |  1 |  1
  Cleaned          |  0 |  0 |  0

Total in 152 ms
Watching for changes in /Users/marvin/mysite/{content,data,layouts,static,themes}
Watching for config changes in /Users/marvin/mysite/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

Go to browser and type http://localhost:1313/ in the URL to see the new post.

Hugo first post

For official documentation on how to install Hugo, visit https://gohugo.io/getting-started/installing/

Show comments