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.

Top comments (11)

Collapse
 
j3rg profile image
Jorgen Ordonez

Thanks this helped. I had some minor differences in steps I took, which I will list below:

  • I use zsh so I edited .zshrc instead
  • Then after I reload the rc file using source ~/.zshrc instead of spawning a new shell.
Collapse
 
ikesalmonson profile image
Luiz Henrique F Salmonson

Thank you. Update for current version and zsh user commands:
wget https://dl.google.com/go/go1.21.3.linux-amd64.tar.gz
sudo tar -xvf go1.21.3.linux-amd64.tar.gz
sudo mv go /usr/local
echo "export GOROOT=/usr/local/go" >> ~/.zshrc
echo "export GOPATH=\$HOME/go" >> ~/.zshrc
echo "export PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH" >> ~/.zshrc
source ~/.zshrc

Collapse
 
it0dan profile image
D.aȠ

The same for me!

Collapse
 
louiemartin profile image
LouieMartin

You can use nano .bashrc instead of File Explorer.

Collapse
 
just_nodes profile image
Justin

Thanks for this, worked perfectly 👌

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

Collapse
 
parmarujjaval3 profile image
Parmar Ujjaval

even simpler use neovim or vi or vim

Collapse
 
asross311 profile image
Andrew Ross

Perfect, thanks man

Collapse
 
fricardi profile image
FRicardi

Just used it - worked great. Thanks!

Collapse
 
extremelysunnyyk profile image
Chia Yong Kang

workedp amazing

Collapse
 
chinwendu20 profile image
Maureen Ononiwu

Thank you so so so much!!

Collapse
 
it0dan profile image
D.aȠ

Thanks! Almost everything works fine!