Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

$ sudo rm -rf /usr/local/go

2. Install the new version

Go to the downloads page and download the binary release suitable for your system.

3. Extract the archive file

To extract the archive file:

$ sudo tar -C /usr/local -xzf /home/nikhita/Downloads/go1.8.1.linux-amd64.tar.gz

4. Make sure that your PATH contains /usr/local/go/bin

$ echo $PATH | grep "/usr/local/go/bin"
@udhos

This comment has been minimized.

Copy link

commented Feb 13, 2018

I have sketched a simple script to automate the task:

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
@alberthuynh91

This comment has been minimized.

Copy link

commented Mar 3, 2018

Thanks @udhos! That script worked perfectly!

@Sunnepah

This comment has been minimized.

Copy link

commented Mar 6, 2018

Thank you @nikhita for sharing and @udhos for the script.

@mehmetsefabalik

This comment has been minimized.

Copy link

commented Apr 3, 2018

@udhos thanks so much 👍

@tevin-morake

This comment has been minimized.

Copy link

commented Apr 3, 2018

You are awesome# @nikhita !
Thank you

@saifiifazal

This comment has been minimized.

Copy link

commented Apr 12, 2018

why its still showing as 1.6.2 after running script? am i doing something wrong?

@kop7

This comment has been minimized.

Copy link

commented Apr 20, 2018

Thanks @udhos

@akkida746

This comment has been minimized.

Copy link

commented Apr 25, 2018

Will the script work on windows7 as well? pls confirm..

@AdminXVII

This comment has been minimized.

Copy link

commented May 19, 2018

@akkida746 No, it's a bash script. It is not compatible with Windows' shell

@matias-alaniz

This comment has been minimized.

Copy link

commented Jun 13, 2018

@udhos it works like a charm!

@safakoks

This comment has been minimized.

Copy link

commented Jul 6, 2018

@udhos thanks a lot!!

@knurherb

This comment has been minimized.

Copy link

commented Jul 16, 2018

Nice

@kedoska

This comment has been minimized.

Copy link

commented Aug 5, 2018

thanks @udhos works perfectly on my linux box

@nitishbhushan2013

This comment has been minimized.

Copy link

commented Aug 8, 2018

thanks udhos, script worked flawlessly on mac

@anujpahade

This comment has been minimized.

Copy link

commented Aug 16, 2018

@saifiifazal I have the same problem.
It's showing the old version even after running the script.
Here is a screenshot.
golangversionproblem

@Clanwarz

This comment has been minimized.

Copy link

commented Aug 28, 2018

Remove your previous install first?

apt-get purge golang-go
rm -rvf /usr/local/go/

Remove any mention of go in e.g. your ~/.bashrc and then do command

whereis go

@rubanraj54

This comment has been minimized.

Copy link

commented Sep 12, 2018

@udhos Script worked perfectly

@DaniRumpi

This comment has been minimized.

Copy link

commented Sep 13, 2018

@udhos your script works perfec. Thanks!

@nabePi

This comment has been minimized.

Copy link

commented Oct 2, 2018

@udhos thanks for script

@sidelux

This comment has been minimized.

Copy link

commented Oct 4, 2018

@udhos Thanks for the script!

@thingdiputra

This comment has been minimized.

Copy link

commented Oct 19, 2018

Thank you @nikhita and @udhos !

@abousselmi

This comment has been minimized.

Copy link

commented Nov 8, 2018

Thanks for this gist. It's funny ! after completing all the tasks you find the script of the first comment. It would be nice if it was included directly in the gist. Thank you.

@fearphage

This comment has been minimized.

Copy link

commented Nov 24, 2018

There's no need to delete the old copy. You can just overwrite it. Here's a one-liner that should work for Linux and MacOS:

curl --silent https://storage.googleapis.com/golang/$(curl --silent https://golang.org/doc/devel/release.html | grep -Eo 'go[0-9]+(\.[0-9]+)+' | sort -V | uniq | tail -1).$(uname -s | tr '[:upper:]' '[:lower:]')-$(case "$(uname -m)" in i*) echo '386' ;; x*) echo 'amd64' ;; *) echo 'armv61'; esac).tar.gz  | sudo tar -vxz --strip-components 1 -C $(dirname $(dirname $(which go)))

It always grabs the latest version and overwrites whatever is in your path (based on which go). I've only tested it on Linux since that's all I have access to. Let me know if you have any issues with it and I'll fix it.

PS. Here's a multi-line more verbose version:

release=$(curl --silent https://golang.org/doc/devel/release.html | grep -Eo 'go[0-9]+(\.[0-9]+)+' | sort -V | uniq | tail -1)
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(case "$(uname -m)" in i*) echo '386' ;; x*) echo 'amd64' ;; *) echo 'armv61'; esac)

curl --silent https://storage.googleapis.com/golang/$release.$os-$arch.tar.gz \
  | sudo tar -vxz --strip-components 1 -C $(dirname $(dirname $(which go)))
@fabienthetis

This comment has been minimized.

Copy link

commented Dec 8, 2018

brew upgrade go

@thevaleriemack

This comment has been minimized.

Copy link

commented Jan 21, 2019

@fabienthetis real mvp

@huglav

This comment has been minimized.

Copy link

commented Jan 31, 2019

brew upgrade go

Did the job, thanks!
I was trying to tweak @fearphage one-liner. Because my mac (sierra 10.12.6) does not support the -V sort option!
Then I saw @fabienthetis comment!!!!!
So K.I.S.S.

@SamwiseGambgee

This comment has been minimized.

Copy link

commented Mar 13, 2019

Thanks a ton!

@rimste

This comment has been minimized.

Copy link

commented Mar 23, 2019

Thanks !

@leejh3224

This comment has been minimized.

Copy link

commented Mar 28, 2019

Awesome!

@xhafid

This comment has been minimized.

Copy link

commented Mar 29, 2019

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

@udhos Its Works in Centos. Good and Thanks

@wmuha

This comment has been minimized.

Copy link

commented Apr 4, 2019

@udhos Thanks, work perfect!

@adammathieu

This comment has been minimized.

Copy link

commented Apr 9, 2019

@udhos, really great. Thanks!

@sergeyklay

This comment has been minimized.

Copy link

commented Apr 10, 2019

@udhos, Thank you very much!

@luckylittle

This comment has been minimized.

Copy link

commented Apr 12, 2019

Alternative, when you don't mind having multiple different versions:

go get golang.org/dl/go1.12.4
go1.12.4 download
go1.12.4 version
@KikiCS

This comment has been minimized.

Copy link

commented Apr 18, 2019

The one-liner provided by @fearphage worked perfectly for me! ^__^

@FaridehGhani

This comment has been minimized.

Copy link

commented Apr 23, 2019

@fearphage It works for me on Ubuntu 18.04. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.