How to Install Golang on WSL/WSL2

0 min read 140 words

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

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

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

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

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts