When a new version of Go comes out, I usually upgrade immediately. This has never caused a problem for me. Most software projects occasionally have an issue where something unintentional happens with a release. That has happened with Go, but it’s never affected me.

For example, Go 1.12.2 was released on April 5 and caused an issue for some Linux users because the version of GCC used to create the binary was too new. A quick fix was released three days later – but there was a mistake and the fix didn’t make it into the release. So a new release came out three days after that, and it finally resolved the issue. Six days, and if you were aware of the issue and it affected you, you could easily switch to the previous version of Go even if you had installed latest.

I say “easily,” but it’s still easier with a simple bash function. The slightly more complicated one is for installation, but that’s pretty simple too. Here’s a function I use to download and install a version of Go on Fedora 30 and make that my new default version:

ginst () {    
    curl https://dl.google.com/go/go$1.linux-amd64.tar.gz -o $HOME/Downloads/go$1.linux-amd64.tar.gz    
    sudo rm /usr/local/go    
    sudo tar -C /usr/local -xzf $HOME/Downloads/go$1.linux-amd64.tar.gz    
    sudo mv /usr/local/go /usr/local/go$1    
    sudo ln -s /usr/local/go$1 /usr/local/go    
    rm $HOME/Downloads/go$1.linux-amd64.tar.gz    
    go version    
}

I put that in my .bashrc. For another operating system or architecture you just need to change the linux-amd64 strings. So for a MacBook, it’s this, and you put it in your .bash_profile (unless you created a .bashrc):

ginst () {
    curl https://dl.google.com/go/go$1.darwin-amd64.tar.gz -o $HOME/Downloads/go$1.darwin-amd64.tar.gz
    sudo rm /usr/local/go
    sudo tar -C /usr/local -xzf $HOME/Downloads/go$1.darwin-amd64.tar.gz
    sudo mv /usr/local/go /usr/local/go$1
    sudo ln -s /usr/local/go$1 /usr/local/go
    rm $HOME/Downloads/go$1.darwin-amd64.tar.gz
    go version
}

Now to get Go 1.13.1, I just do this:

$ ginst 1.13.1

Sudo prompts me for password, and then I have it. You need to sudo because access to /usr/local is restricted. If you want to install to your home directory, there’s no need to sudo, and you can change the function to do that.

You could improve on these scripts by checking version availability, computing and comparing checksums, and automatically detecting the operating system and architecture. But these are good enough for me, at least for now.

I’ve found there are good reasons to upgrade Go quickly: security patches, bug fixes, and performance improvements. For my own projects, I have never needed to go back to a previous version. But occasionally, for experimentation or when working on someone else’s project, I might need to go back. So here’s a simple function to switch versions, assuming you installed via the above method:

gver () {    
    sudo rm /usr/local/go    
    sudo ln -s /usr/local/go$1 /usr/local/go    
    go version    
} 

It’s just three lines copied from the other function: it deletes a symbolic link, and creates a new one pointing to the specified version. Source that and you can switch versions with:

$ gver 1.12.7