Installing dev hugo

Hi - I’m using this zsh function to upgrade hugo:

hugodevinstall (){
  cd $HOME
  echo "==Move current hugo to hugo-prev in case of need to revert=="
  mv $HOME/gocode/bin/hugo $HOME/gocode/bin/hugo-prev
  echo "==Upgrading Hugo Source=="
  go get -u -v github.com/spf13/hugo
  echo "==Get newly installed hugo version=="
  $HOME/gocode/bin/hugo version
  echo "==Compile new hugo=="
  cd $HOME/gocode/src/github.com/spf13/hugo/
  make hugo
  echo "==Get version string and move hugo into position=="
  _newhugoverstr=$($HOME/gocode/src/github.com/spf13/hugo/hugo version | awk -F ' ' '{ print $5 }')
  mv $HOME/gocode/src/github.com/spf13/hugo/hugo $HOME/gocode/bin/hugo-${_newhugoverstr}
  cd $HOME/gocode/bin
  ln -sf $HOME/gocode/bin/hugo-${_newhugoverstr} hugo
  cd $HOME
  echo "==Sanity check - compare versions=="
  echo "Expecting: ${_newhugoverstr}"
  echo "Actual: "
  hugo version
}

I have GOPATH=/Users/rcogley/gocode, and my go version is 1.8.1. This function script worked when I had not upgraded for a while, but, today I thought I’d run it with the idea that I’d get the latest, but, I think that some things have changed.

This is what it returns when I run it now:

hugodevinstall
==Move current hugo to hugo-prev in case of need to revert==
overwrite /Users/rcogley/gocode/bin/hugo-prev? (y/n [n]) y
==Upgrading Hugo Source==
github.com/spf13/hugo (download)
# cd /Users/rcogley/gocode/src/github.com/spf13/hugo; git pull --ff-only
From https://github.com/spf13/hugo
   b332d93e..718c0e14  master       -> origin/master
 + b41518ed...92a51a53 release-docs -> origin/release-docs  (forced update)
 * [new branch]        v0.18.1rb    -> origin/v0.18.1rb
 * [new branch]        v0.20.5rb    -> origin/v0.20.5rb
 * [new branch]        v0.20.6rb    -> origin/v0.20.6rb
 * [new tag]           v0.20.5      -> v0.20.5
 * [new tag]           v0.20.6      -> v0.20.6
error: Your local changes to the following files would be overwritten by merge:
	vendor/vendor.json
Please commit your changes or stash them before you merge.
Aborting
Updating b5e32eb6..718c0e14
package github.com/spf13/hugo: exit status 1
  0.27s user 0.97s system 51% cpu 2.406 total
==Get newly installed hugo version==
hugodevinstall:7: no such file or directory: /Users/rcogley/gocode/bin/hugo
==Compile new hugo==
go get github.com/kardianos/govendor
govendor sync github.com/spf13/hugo
go build -ldflags "-X github.com/spf13/hugo/hugolib.CommitHash=`git rev-parse --short HEAD 2>/dev/null` -X github.com/spf13/hugo/hugolib.BuildDate=`date +%FT%T%z`" github.com/spf13/hugo
  1.25s user 0.66s system 88% cpu 2.165 total
==Get version string and move hugo into position==
overwrite /Users/rcogley/gocode/bin/hugo-v0.21-DEV-B5E32EB6? (y/n [n]) y
==Sanity check - compare versions==
Expecting: v0.21-DEV-B5E32EB6
Actual:
Hugo Static Site Generator v0.21-DEV-B5E32EB6 darwin/amd64 BuildDate: 2017-04-27T19:10:01+09:00

Well, nothing changes and I just want to understand the best practice for getting the latest, doing an upgrade and so on.

Can someone please advise, if you happen to have a stable script for upgrade?

Thank you in advance. :slightly_smiling:

おはようございます @RickCogley

Have you tried installing Hugo since we move to govendor? I had to work out some quirks (self-imposed) with my path, but this is what I’m currently using to install from source on macOS.

https://hugodocs.info/getting-started/installing/#source

(Same info on gohugo.io as well as the docs concept above.)

I install the dev version of hugo using a little bash script. I had written a blog post about it. Everything in that script would apply to you, except that you can comment out govendor fetch github.com/chaseadamsio/goorgeous if you do not care about using the latest version of the goorgeous package.

Thanks @rdwatters and @kaushalmodi, much appreciated. I’ll give those a “go”. (I’m easily amused).

The main docs site is not as detailed as the hugodocs site in this respect. I should have looked there.

@kaushalmodi hi, your bash script helped me a lot. Could you please advise what is the purpose of the -ldflags?

go install -v \
   -ldflags "-X ${package}/hugolib.CommitHash=${commithash} \
             -X ${package}/hugolib.BuildDate=${builddate}" \
   ${package} 

I assume that that bakes in the commit hash and build date somewhere, but, where can I view those?

hugo version and hugo env show those values.

Thanks @bep :slightly_smiling:

They also populate the internal CommitHash and BuildDate variables which I use I like this in my HTML headers:

    <!-- Hugo info -->
    {{ printf "<!--Hugo Build Date: %s-->" .Hugo.BuildDate | safeHTML }}
    {{ printf "<!--Hugo Commit Hash: %s-->" .Hugo.CommitHash | safeHTML }}

and that shows up like this when I view the page sources of my blog:

  • Use of this in my theme
1 Like

@kaushalmodi, right, thanks!