Skip to content

How to Install Golang on WSL/WSL2

If you need to install Golang on WSL under Windows 10 or higher, you can follow these few steps.

First remove any old versions lying around

sudo rm -rf /usr/local/go* && sudo rm -rf /usr/local/go
Code language: Bash (bash)

Determine the latest Go version

Go to https://golang.org/dl/ and find out what the latest version is. At the time of writing this, Go is on version 1.16.

Install Go

Make sure to replace 1.16 below with the updated version as required.

VERSION=1.16 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
Code language: Bash (bash)

Add Go to your environment profile

Open ~/.bashrc and add the following. Remember to update the 1.16 to the version you installed.

export GOROOT=/usr/local/go-1.16 export GOPATH=$HOME/projects/go export GOBIN=$GOPATH/bin export PATH=$PATH:$GOROOT/bin export PATH=$PATH:$HOME/projects/go/bin
Code language: Bash (bash)

You will now be able to run Go by typing go in the WSL terminal.

See also  The Decoded String at Index using Java
Tags:
Subscribe
Notify of
guest
7 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
lior
1 month ago

actually the wget didnt work – went to golang.org installation for it:https://go.dev/doc/install

this also takes care for the path update, too

Patrick Warburton
Patrick Warburton
4 months ago

Hi, silly question here.
How do I open this ~/.bashrc?
There aren’t many guides on the internet to go on.
I’ve opened it using cat .bashrc, but it’s giving me an interface that i find quite confusing, in that it doesn’t offer an obvious place to input the lines of code you include in the second grey box.

Thanks

Patrick Warburton
Patrick Warburton
4 months ago
Reply to  Andrew

Thanks for your help. I’ve figured the bashrc file out successfully.
However, when I run go version I get 1.13.8.
This is the fourth or so time that I’ve installed go, each time it installs this version.
Do you know why this could be?

Thanks

Patrick Warburton
Patrick Warburton
4 months ago

Thanks for the help. I’ve sorted it now

J. R.
J. R.
2 months ago

How did you fix it? Mine is doing the same thing!

Chavez
Chavez
5 months ago

Awesome post, It helped alot. Thank you.

7
0
Would love your thoughts, please comment.x
()
x