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 (19)

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
 
talk2onyx profile image
Olaleye Obidiya

Thanks, this works for bashrc also.

wget https://dl.google.com/go/go1.23.0.linux-amd64.tar.gz
sudo tar -xvf go1.23.0.linux-amd64.tar.gz
sudo mv go /usr/local
echo "export GOROOT=/usr/local/go" >> ~/.bashrc
echo "export GOPATH=\$HOME/go" >> ~/.bashrc
echo "export PATH=\$GOPATH/bin:\$GOROOT/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
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
 
ujjaval999 profile image
Parmar Ujjaval

even simpler use neovim or vi or vim

Collapse
 
asross311 profile image
Andrew Ross

Perfect, thanks man

Collapse
 
nurudeeen profile image
Nurudeen Rabiu Alabi

very helpful, thanks

Collapse
 
mogueno profile image
Mogueno

Be sure to always go to go.dev/dl/ to check the latest go version when downloading the .tar.gz!

Collapse
 
nathankurz91 profile image
Nathan Kurz

Hell yeah! Nice and easy, thanks!

Collapse
 
fricardi profile image
FRicardi

Just used it - worked great. Thanks!

Collapse
 
extremelysunnyyk profile image
Chia Yong Kang

workedp amazing