DEV Community

Mrityunjaya Prajapati
Mrityunjaya Prajapati

Posted on

How to Install Golang on WSL/WSL2

One of the best feature that Windows 10 or 11 Pro support is WSL or WSL2, using this you can run any Linux OS like a windows application.

If you want to install GoLang on WSL/WSL2 and setup your development environment, please follow these steps

Check Latest Go Version

You can check latest Go Version for any OS like: Linux, macOS or Windows at https://go.dev/dl/

Install Go

At the time of writing this blog, the most recent LTS version of Go is 1.18.3.

wget https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz
sudo tar -xvf go1.18.3.linux-amd64.tar.gz
sudo mv go /usr/local

Edit .bashrc file

You have to edit .bashrc file before making further changes, you can follow below steps to open .bashrc file

cd ~
explorer.exe .

Open .bashrc file and add following lines at the bottom and save the file.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Refresh your terminal using **bash **command

Check Go Version

go version

Make sure it returns the same version that you installed.

Discussion (2)

Collapse
extremelysunnyyk profile image
Chia Yong Kang

workedp amazing

Collapse
just_nodes profile image
Justin

Thanks for this, worked perfectly 👌

You can also use $ code ~/.bashrc instead of explorer.exe .