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

@udhos udhos 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

@alberthuynh91 alberthuynh91 commented Mar 3, 2018

Thanks @udhos! That script worked perfectly!

@Sunnepah

This comment has been minimized.

Copy link

@Sunnepah Sunnepah commented Mar 6, 2018

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

@mehmetsefabalik

This comment has been minimized.

Copy link

@mehmetsefabalik mehmetsefabalik commented Apr 3, 2018

@udhos thanks so much 👍

@tevin-morake

This comment has been minimized.

Copy link

@tevin-morake tevin-morake commented Apr 3, 2018

You are awesome# @nikhita !
Thank you

@saifiifazal

This comment has been minimized.

Copy link

@saifiifazal saifiifazal 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

@kop7 kop7 commented Apr 20, 2018

Thanks @udhos

@akkida746

This comment has been minimized.

Copy link

@akkida746 akkida746 commented Apr 25, 2018

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

@AdminXVII

This comment has been minimized.

Copy link

@AdminXVII AdminXVII 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

@matias-alaniz matias-alaniz commented Jun 13, 2018

@udhos it works like a charm!

@safakoks

This comment has been minimized.

Copy link

@safakoks safakoks commented Jul 6, 2018

@udhos thanks a lot!!

@knurherb

This comment has been minimized.

Copy link

@knurherb knurherb commented Jul 16, 2018

Nice

@kedoska

This comment has been minimized.

Copy link

@kedoska kedoska commented Aug 5, 2018

thanks @udhos works perfectly on my linux box

@nitishbhushan2013

This comment has been minimized.

Copy link

@nitishbhushan2013 nitishbhushan2013 commented Aug 8, 2018

thanks udhos, script worked flawlessly on mac

@anujpahade

This comment has been minimized.

Copy link

@anujpahade anujpahade 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

@Clanwarz Clanwarz 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

@rubanraj54 rubanraj54 commented Sep 12, 2018

@udhos Script worked perfectly

@DaniRumpi

This comment has been minimized.

Copy link

@DaniRumpi DaniRumpi commented Sep 13, 2018

@udhos your script works perfec. Thanks!

@nabePi

This comment has been minimized.

Copy link

@nabePi nabePi commented Oct 2, 2018

@udhos thanks for script

@sidelux

This comment has been minimized.

Copy link

@sidelux sidelux commented Oct 4, 2018

@udhos Thanks for the script!

@thingdiputra

This comment has been minimized.

Copy link

@thingdiputra thingdiputra commented Oct 19, 2018

Thank you @nikhita and @udhos !

@abousselmi

This comment has been minimized.

Copy link

@abousselmi abousselmi 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

@fearphage fearphage 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)))

EDIT: When you paste the one-liner into zsh, it inserts a single backslash (\) after the first dollar sign ($). It looks like /golang/$\(curl instead of /golang/$(curl. You have to remove that backslash or you'll get the following error: zsh: parse error near ')'.

@fabienthetis

This comment has been minimized.

Copy link

@fabienthetis fabienthetis commented Dec 8, 2018

brew upgrade go

@valmack

This comment has been minimized.

Copy link

@valmack valmack commented Jan 21, 2019

@fabienthetis real mvp

@huglav

This comment has been minimized.

Copy link

@huglav huglav 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.

@chetan-hireholi

This comment has been minimized.

Copy link

@chetan-hireholi chetan-hireholi commented Mar 13, 2019

Thanks a ton!

@rimste

This comment has been minimized.

Copy link

@rimste rimste commented Mar 23, 2019

Thanks !

@leejh3224

This comment has been minimized.

Copy link

@leejh3224 leejh3224 commented Mar 28, 2019

Awesome!

@xhafid

This comment has been minimized.

Copy link

@xhafid xhafid 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

@wmuha wmuha commented Apr 4, 2019

@udhos Thanks, work perfect!

@adammathieu

This comment has been minimized.

Copy link

@adammathieu adammathieu commented Apr 9, 2019

@udhos, really great. Thanks!

@sergeyklay

This comment has been minimized.

Copy link

@sergeyklay sergeyklay commented Apr 10, 2019

@udhos, Thank you very much!

@luckylittle

This comment has been minimized.

Copy link

@luckylittle luckylittle 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

@KikiCS KikiCS commented Apr 18, 2019

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

@FaridehGhani

This comment has been minimized.

Copy link

@FaridehGhani FaridehGhani commented Apr 23, 2019

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

@imyhui

This comment has been minimized.

Copy link

@imyhui imyhui commented May 13, 2019

In Mac OS,Just download Official binary distributions and Install again .

@safwan-moha

This comment has been minimized.

Copy link

@safwan-moha safwan-moha commented May 16, 2019

Thanks @udhos! That script worked nicely!

@danielhnmoreno

This comment has been minimized.

Copy link

@danielhnmoreno danielhnmoreno commented May 20, 2019

EXCELENT!

@helayoty

This comment has been minimized.

Copy link

@helayoty helayoty commented Jun 16, 2019

@udhos Thanks!

@hajidalakhtar

This comment has been minimized.

Copy link

@hajidalakhtar hajidalakhtar commented Jun 18, 2019

Thank you very much!

@wpexia

This comment has been minimized.

Copy link

@wpexia wpexia commented Jul 18, 2019

@udhos Script worked perfectly, thank you very much!

@dayadev

This comment has been minimized.

Copy link

@dayadev dayadev commented Jul 25, 2019

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

U get this error
update-golang.sh: die: could not download using curl from: https://storage.googleapis.com/golang/go1.12.7.darwin-amd64.tar.gz

@stevecw

This comment has been minimized.

Copy link

@stevecw stevecw commented Jul 25, 2019

I tried the one liner from @fearphage, but got a zsh: parse error near ')', so I ran his final curl --silent command after replacing his variables with the values I obtained when I ran each of his 'release', 'os' and 'arch' one-liners one at a time (beforehand).

curl --silent https://storage.googleapis.com/golang/go1.12.7.darwin-amd64.tar.gz | sudo tar -vxz --strip-components 1 -C /usr/local/go

Worked perfectly! Thanks :)

@fearphage

This comment has been minimized.

Copy link

@fearphage fearphage commented Jul 25, 2019

I tried the one liner from @fearphage, but got a zsh: parse error near ')'

When you paste it in, for some reason the shell tries to escape some things. It inserts a single backslash (\) after the first $. It looks like /golang/$\(curl instead of /golang/$(curl. This is what is breaking it. Remove that backslash and you're good to go. I'm not sure how to paste without that auto-correct.

EDIT: This seems to be a function of zsh trying to be helpful... although it is not in this case.

@udhos

This comment has been minimized.

Copy link

@udhos udhos commented Jul 29, 2019

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

U get this error
update-golang.sh: die: could not download using curl from: https://storage.googleapis.com/golang/go1.12.7.darwin-amd64.tar.gz

Do you have 'curl' on your system? The scripts depends on either 'wget' or 'curl' to download the release.

@TankyH

This comment has been minimized.

Copy link

@TankyH TankyH commented Aug 6, 2019

works perfect @udhos

@Eroschang

This comment has been minimized.

Copy link

@Eroschang Eroschang commented Sep 2, 2019

@udhos and @fearphage thanks a lot of you !!!

@ishankhare07

This comment has been minimized.

Copy link

@ishankhare07 ishankhare07 commented Sep 11, 2019

Interesting that no one mentioned gvm

@tatecapone

This comment has been minimized.

Copy link

@tatecapone tatecapone commented Sep 11, 2019

udhos your script work perfect.
a doubt, should I delete the previous version that is renamed by the script
thanks!

@udhos

This comment has been minimized.

Copy link

@udhos udhos commented Sep 12, 2019

@tatecapone yes, unless you have some special need to keep it.

@evritt

This comment has been minimized.

Copy link

@evritt evritt commented Sep 13, 2019

@fabienthetis thanks

@tatecapone

This comment has been minimized.

Copy link

@tatecapone tatecapone commented Sep 13, 2019

@sumgr0

This comment has been minimized.

Copy link

@sumgr0 sumgr0 commented Sep 15, 2019

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)))

EDIT: When you paste the one-liner into zsh, it inserts a single backslash (\) after the first dollar sign ($). It looks like /golang/$\(curl instead of /golang/$(curl. You have to remove that backslash or you'll get the following error: zsh: parse error near ')'.

This worked perfectly for me. Thanks
PS: Since using the zsh, that last tip was a strange finding though

@dan-compton

This comment has been minimized.

Copy link

@dan-compton dan-compton commented Sep 26, 2019

Great script ^ works fine for bash as well:

goupdate() {
  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)))
  source ~/.bashrc
  echo "updated to $(go version)"
}
@jontunjon

This comment has been minimized.

Copy link

@jontunjon jontunjon commented Oct 1, 2019

Obrigado @udhos! Worked like a charm on Mac :)

@smithaitufe

This comment has been minimized.

Copy link

@smithaitufe smithaitufe commented Oct 29, 2019

Thanks @udhos. Worked perfectly.

@wschwab

This comment has been minimized.

Copy link

@wschwab wschwab commented Nov 1, 2019

Just used @fearphage 's script:

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)))

worked like a charm

@jmgbsas

This comment has been minimized.

Copy link

@jmgbsas jmgbsas commented Nov 3, 2019

and the packages previously installed will continue runing and do not losted? Thanks.

@dan-compton

This comment has been minimized.

Copy link

@dan-compton dan-compton commented Nov 4, 2019

Who can make this script the shortest? go!

@MrMebelMan

This comment has been minimized.

Copy link

@MrMebelMan MrMebelMan commented Dec 3, 2019

The tar command has an incorrect go version (go1.8.1.linux-amd64.tar.gz instead of go1.13.4.linux-amd64.tar.gz)

@AndreiD

This comment has been minimized.

Copy link

@AndreiD AndreiD commented Dec 6, 2019

no need for all that fancy stuff

cd /tmp
wget -q https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x installer_linux
./installer_linux
source /home/YOUR_USER/.zshrc
go version
@saharavishag

This comment has been minimized.

Copy link

@saharavishag saharavishag commented Dec 9, 2019

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

Thanks! work great!

@ayooki

This comment has been minimized.

Copy link

@ayooki ayooki commented Dec 27, 2019

@udhos. Thanks your script worked!

@cskonopka

This comment has been minimized.

Copy link

@cskonopka cskonopka commented Dec 28, 2019

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

Thanks! work great!

Worked perfectly!

@sacpwrmll

This comment has been minimized.

Copy link

@sacpwrmll sacpwrmll commented Jan 12, 2020

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

@silasvasconcelos

This comment has been minimized.

Copy link

@silasvasconcelos silasvasconcelos commented Jan 24, 2020

Thank you @udhos for the script.

@jurgen-kluft

This comment has been minimized.

Copy link

@jurgen-kluft jurgen-kluft commented Feb 7, 2020

Thank you @udhos for the script.

@mateusprado

This comment has been minimized.

Copy link

@mateusprado mateusprado commented Feb 27, 2020

easier than that, just buying ready at the bakery! thanks @udhos for the script.

@changjunpyo

This comment has been minimized.

Copy link

@changjunpyo changjunpyo commented Feb 27, 2020

Thank you @udhos for the script. I easily update to 1.14

@barokurniawan

This comment has been minimized.

Copy link

@barokurniawan barokurniawan commented Mar 5, 2020

@udhos thanks for saving my time

@VictorUUsoro

This comment has been minimized.

Copy link

@VictorUUsoro VictorUUsoro commented Mar 10, 2020

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

tried this and it's not working

@udhos

This comment has been minimized.

Copy link

@udhos udhos commented Mar 10, 2020

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

tried this and it's not working

File an issue reporting the error: https://github.com/udhos/update-golang/issues

@storm1kk

This comment has been minimized.

Copy link

@storm1kk storm1kk commented Mar 20, 2020

Thank you @udhos for the script!

@kingsleytan

This comment has been minimized.

Copy link

@kingsleytan kingsleytan commented Mar 23, 2020

@udhos Script worked perfectly, thank you very much!

@majidkarimizadeh

This comment has been minimized.

Copy link

@majidkarimizadeh majidkarimizadeh commented Apr 1, 2020

@udhos WooW...thanks

@cauldyclark15

This comment has been minimized.

Copy link

@cauldyclark15 cauldyclark15 commented Apr 27, 2020

after saying it is success on upgrade, go version still outputs an old golang version, not v1.14
go version go1.10.2 darwin/amd64
I am using @udhos script https://github.com/udhos/update-golang

does anyone from you guys experiencing the same? thanks btw for all the shared help here

@shao-shuai

This comment has been minimized.

Copy link

@shao-shuai shao-shuai commented May 2, 2020

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

Thank you~

@chefgs

This comment has been minimized.

Copy link

@chefgs chefgs commented May 9, 2020

Thanks @nikhita and @udhos

@luthfiazzz

This comment has been minimized.

Copy link

@luthfiazzz luthfiazzz commented May 11, 2020

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

@udhos it's work in ubuntu thanks

@ATMackay

This comment has been minimized.

Copy link

@ATMackay ATMackay commented May 19, 2020

Thanks @udhos

@ZhengxunWu

This comment has been minimized.

Copy link

@ZhengxunWu ZhengxunWu commented May 24, 2020

script to automate the

that's not simple script, how do i upgrade to a certain version instead of upgrading to latest version?

@udhos

This comment has been minimized.

Copy link

@udhos udhos commented May 24, 2020

script to automate the

that's not simple script, how do i upgrade to a certain version instead of upgrading to latest version?

In the docs one can find this example:

sudo RELEASE=1.9beta1 ./update-golang.sh

Full docs:
https://github.com/udhos/update-golang/blob/master/README.md#customization

@abhie19

This comment has been minimized.

Copy link

@abhie19 abhie19 commented May 24, 2020

Still works great. Thanks @udhos

@jay-manday

This comment has been minimized.

Copy link

@jay-manday jay-manday commented May 25, 2020

ditto, @udhos thanks dude

@chikondot

This comment has been minimized.

Copy link

@chikondot chikondot commented Jun 10, 2020

@udhos thank you, this script is brilliant 👌🏾

@Swarag-N

This comment has been minimized.

Copy link

@Swarag-N Swarag-N commented Jun 12, 2020

@udhos thank you, I tried it in WSL.
but it would be better if the user has an option to choose whether to have the old go version or not.

@udhos

This comment has been minimized.

Copy link

@udhos udhos commented Jun 13, 2020

@udhos thank you, I tried it in WSL.
but it would be better if the user has an option to choose whether to have the old go version or not.

You could easily switch back to the previous version, if you know its release number:

sudo RELEASE=1.9beta1 ./update-golang.sh

@jaybowles

This comment has been minimized.

Copy link

@jaybowles jaybowles commented Jun 24, 2020

@udhos you absolute legend

@Drakx

This comment has been minimized.

Copy link

@Drakx Drakx commented Jul 15, 2020

@udhos works perfectly on macOS. Thank you!

@ahampriyanshu

This comment has been minimized.

Copy link

@ahampriyanshu ahampriyanshu commented Jul 18, 2020

Thanks @udhos

@jaisharmafps

This comment has been minimized.

Copy link

@jaisharmafps jaisharmafps commented Aug 18, 2020

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

Thanks man!

@dhkim2020

This comment has been minimized.

Copy link

@dhkim2020 dhkim2020 commented Aug 28, 2020

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

Thanks!!! @udhos

@Yuggupta27

This comment has been minimized.

Copy link

@Yuggupta27 Yuggupta27 commented Sep 29, 2020

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

Thanks for the Script! Works like a charm :)

@gimsesu

This comment has been minimized.

Copy link

@gimsesu gimsesu commented Oct 16, 2020

Thank you!

@dpthegrey

This comment has been minimized.

Copy link

@dpthegrey dpthegrey commented Nov 18, 2020

brew upgrade go

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.