How to install Go(lang) and Hugo on Ubuntu.

Install Go

Reference: https://golang.org/doc/install

Replace the https://… download URL below with the latest Linux AMD64 version listed at https://golang.org/dl/

For an upgrade install, only the first 5 lines below are required.

sudo rm -rf /usr/local/go
cd $HOME
curl -OL https://storage.googleapis.com/golang/go1.9.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf $HOME/go1.9.4.linux-amd64.tar.gz
rm $HOME/go1.9.4.linux-amd64.tar.gz
mkdir $HOME/go/bin -p
mkdir $HOME/go/pkg
mkdir $HOME/go/src
echo "PATH=\$PATH:/usr/local/go/bin" >> .profile
echo "PATH=\$PATH:\$HOME/go/bin" >> .profile
echo "GOPATH=\$HOME/go" >> .profile
source .profile

Install Hugo

Reference: https://gohugo.io/getting-started/installing/

The first three lines below creates a shell script which will download the latest version of Hugo, compile it with Go, and then install it in the Go bin directory.

The subsequent commands will mark the created script file as executable and then finally run that script.

echo "go get github.com/magefile/mage" > hugo-from-gh.sh
echo "go get -u -d github.com/gohugoio/hugo" >> hugo-from-gh.sh
echo "cd \$HOME/go/src/github.com/gohugoio/hugo" >> hugo-from-gh.sh
echo "mage vendor" >> hugo-from-gh.sh
echo "mage install" >> hugo-from-gh.sh
chmod +x hugo-from-gh.sh
./hugo-from-gh.sh

To test that all is installed as expected, run the following commands and check that they don’t report a file not found error.

go version
hugo version