yzhe819's Blog

Installing Go in WSL2

2022.06.17

Just a record of installing Go in WSL from the command line.

Configure WSL 2

Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.

To work with WSL 2, your Windows version should be 10 build 18917 or later. Follow these instructions to switch the distributive.

Run Ubuntu

Just enter the wsl from windows 10.

$ bash

Download and Extract

Then download the tarball.

$ wget https://golang.org/dl/go1.17.1.linux-amd64.tar.gz

Extract the archive to /usr/local.

$ sudo tar -C /usr/local -xzf go1.17.1.linux-amd64.tar.gz

Config

Configure the path of go.

$ vim ~/.bashrc

Then, add the following to the end of ~/.bashrc file to configure GOPATH and GOROOT.

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Here is my example:

example

Check

Restart the wsl, then use the following command line to check the version.

$ go -version
go version go1.17.1 linux/amd64

The installation is complete.

Reference

Link: How to use wsl development environment in product

Happy coding.