Hey, do you want to run Linux on your Windows like a boss? Well, you can with WSL or WSL2, which are awesome features of Windows 10 or 11 Pro. And guess what? You can also install GoLang on your WSL/WSL2 and code like a pro. Here’s how:
First, you need to find out the latest and greatest version of Go for your OS. Whether you use Linux, macOS or Windows, you can check it out at https://go.dev/dl/
Next, you need to download and install Go on your WSL/WSL2. At the time of writing this blog, the coolest version of Go is 1.18.3.
To get it, just type these commands in your terminal:
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
Now, you need to tell your WSL/WSL2 where to find Go and where to store your Go projects. To do that, you need to edit a file called .bashrc, which is like a magic spell book for your terminal.
To open it, just type these commands in your terminal:
cd ~
explorer.exe .
Then, open the .bashrc file and add these lines at the end of it:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Save the file and close it. Then, refresh your terminal by typing this command:
bash
Finally, you can check if Go is installed correctly by typing this command:
go version
If you see something like go version go1.18.3 linux/amd64, then congratulations! You have successfully installed Go on your WSL/WSL2 and you are ready to rock! 🎸