Skip to content

Instantly share code, notes, and snippets.

@renevo
Created September 5, 2018 18:56
Show Gist options
  • Save renevo/fad4db582b4f0edb9ecb767dec689474 to your computer and use it in GitHub Desktop.
Save renevo/fad4db582b4f0edb9ecb767dec689474 to your computer and use it in GitHub Desktop.
Easily update/install Go in wsl

Updating/Installing Go in WSL

Remove

Removes older versions

sudo rm -rf /usr/local/go* && sudo rm -rf /usr/local/go

Install

Change version as applicable

VERSION=1.11
OS=linux
ARCH=amd64

cd $HOME
wget https://storage.googleapis.com/golang/go$VERSION.$OS-$ARCH.tar.gz
tar -xvf go$VERSION.$OS-$ARCH.tar.gz
mv go go-$VERSION
sudo mv go-$VERSION /usr/local

Add Go Environment

Open up ~/.bashrc and update/add the following near the bottom (replace with correct go version)

# configure go-1.11
export GOROOT=/usr/local/go-1.11
export GOPATH=$HOME/projects/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$HOME/projects/go/bin
@xordux
Copy link

xordux commented Jun 27, 2021

Some people might still get go command not found error after doing all the above steps in Ubuntu. They will need to edit .profile as well: https://askubuntu.com/a/1105445

I added this in mine (change version accordingly):

# additional setting for golang
if [ -d "/usr/local/go-1.16.5/bin" ] ; then
    PATH=$PATH:/usr/local/go-1.16.5/bin
fi

@renevo
Copy link
Author

renevo commented Aug 27, 2021

Thanks for that :)

@LordJohn42
Copy link

Thank you man.

@rcodina-lealco
Copy link

cuando meto este comando: wget https://storage.googleapis.com/golang/go$VERSION.$OS-$ARCH.tar.gz
Me sale el siguiente error:

Resolving storage.googleapis.com (storage.googleapis.com)... 142.250.78.80, 142.250.78.112, 142.250.78.144, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|142.250.78.80|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2022-02-25 09:30:46 ERROR 404: Not Found.

@Aketos
Copy link

Aketos commented Mar 12, 2022

@rcodina-lealco you haven't probably set

VERSION=1.11
OS=linux
ARCH=amd64

before to run that command :)

@victordavid626
Copy link

Please how do install wsl fresh on a laptop?

I am having issues doing that

@victordavid626
Copy link

Please how do install wsl fresh on a laptop?

I am having issues doing that

@proffatai
Copy link

Please how do install wsl fresh on a laptop?

I am having issues doing that

Checkout Youtube, there are videos there to help you

@snowboarder
Copy link

Please how do install wsl fresh on a laptop?

I am having issues doing that

For WSL you may have to enable SVM (Maybe different name on intel based motherboard bios) under CPU settings in Bios to get it to install, then follow the command instruction to install on Microsoft website

@SarvinTorkaman
Copy link

Thanks!

@xordux
Copy link

xordux commented Jan 11, 2023

Please how do install wsl fresh on a laptop?

I am having issues doing that

Youtube shoud've shown you the steps. It's as simple as just running following command in PowerShell (as administrator):
wsl --install

That's all you need. After that restart your system and then search Ubuntu in start menu, it should be available there.

@icewind666
Copy link

Remember that
sudo rm -rf /usr/local/go*
will remove ALL files starting with letters "go" even not related to golang!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment